Skip to content

Commit 6965ac6

Browse files
committed
Result::getColumnMeta is cached (ref #212)
1 parent f88cb81 commit 6965ac6

3 files changed

Lines changed: 29 additions & 2 deletions

File tree

src/Database/Drivers/PDO/Connection.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
class Connection implements Drivers\Connection
1717
{
1818
public readonly PDO $pdo;
19+
public string $resultClass = Result::class;
1920
public string $metaTypeKey = 'native_type';
2021

2122

@@ -40,7 +41,7 @@ public function query(string $sql, array $params = []): Result
4041
}
4142

4243
$statement->execute();
43-
return new Result($statement, $this);
44+
return new ($this->resultClass)($statement, $this);
4445
}
4546

4647

src/Database/Drivers/PDO/PgSQL/Driver.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ public function __construct(
2929

3030
public function connect(): Drivers\Connection
3131
{
32-
return new Drivers\PDO\Connection(...$this->params);
32+
$connection = new Drivers\PDO\Connection(...$this->params);
33+
$connection->resultClass = Result::class;
34+
return $connection;
3335
}
3436

3537

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
/**
4+
* This file is part of the Nette Framework (https://nette.org)
5+
* Copyright (c) 2004 David Grudl (https://davidgrudl.com)
6+
*/
7+
8+
declare(strict_types=1);
9+
10+
namespace Nette\Database\Drivers\PDO\PgSQL;
11+
12+
use Nette\Database\Drivers;
13+
14+
15+
class Result extends Drivers\PDO\Result
16+
{
17+
private static array $columnsCache = [];
18+
19+
20+
protected function collectColumnsInfo(): array
21+
{
22+
return self::$columnsCache[$this->result->queryString] ??= parent::collectColumnsInfo();
23+
}
24+
}

0 commit comments

Comments
 (0)