Skip to content

Commit

Permalink
Result::getColumnMeta is cached (ref #212)
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Aug 29, 2024
1 parent ba2609f commit d4ba565
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/Database/Drivers/PDO/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
class Connection implements Drivers\Connection
{
public readonly PDO $pdo;
public string $resultClass = Result::class;
public string $metaTypeKey = 'native_type';


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

$statement->execute();
return new Result($statement, $this);
return new ($this->resultClass)($statement, $this);
}


Expand Down
4 changes: 3 additions & 1 deletion src/Database/Drivers/PDO/PgSQL/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ public function __construct(

public function connect(): Drivers\Connection
{
return new Drivers\PDO\Connection(...$this->params);
$connection = new Drivers\PDO\Connection(...$this->params);
$connection->resultClass = Result::class;
return $connection;
}


Expand Down
24 changes: 24 additions & 0 deletions src/Database/Drivers/PDO/PgSQL/Result.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

/**
* This file is part of the Nette Framework (https://nette.org)
* Copyright (c) 2004 David Grudl (https://davidgrudl.com)
*/

declare(strict_types=1);

namespace Nette\Database\Drivers\PDO\PgSQL;

use Nette\Database\Drivers;


class Result extends Drivers\PDO\Result
{
private static array $columnsCache = [];


protected function collectColumnsInfo(): array
{
return self::$columnsCache[$this->result->queryString] ??= parent::collectColumnsInfo();
}
}

0 comments on commit d4ba565

Please sign in to comment.