From b8a5777044a59964f32c81015164f87a91a7dc8c Mon Sep 17 00:00:00 2001 From: Tigrov Date: Tue, 3 Dec 2024 15:05:29 +0700 Subject: [PATCH 1/3] Update according changes in `db` package --- src/Connection.php | 13 +++++-------- src/QueryBuilder.php | 19 +++++++++++-------- src/Schema.php | 2 +- tests/QueryBuilderTest.php | 2 +- tests/SchemaTest.php | 8 ++++---- 5 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/Connection.php b/src/Connection.php index 46b57fc43..bacf9c587 100644 --- a/src/Connection.php +++ b/src/Connection.php @@ -55,14 +55,11 @@ public function getLastInsertID(string $sequenceName = null): string public function getQueryBuilder(): QueryBuilderInterface { - if ($this->queryBuilder === null) { - $this->queryBuilder = new QueryBuilder( - $this->getQuoter(), - $this->getSchema(), - ); - } - - return $this->queryBuilder; + return $this->queryBuilder ??= new QueryBuilder( + $this->getQuoter(), + $this->getSchema(), + $this->getServerInfo(), + ); } public function getQuoter(): QuoterInterface diff --git a/src/QueryBuilder.php b/src/QueryBuilder.php index b46c021f9..8f65aea11 100644 --- a/src/QueryBuilder.php +++ b/src/QueryBuilder.php @@ -4,6 +4,7 @@ namespace Yiisoft\Db\Pgsql; +use Yiisoft\Db\Connection\ServerInfoInterface; use Yiisoft\Db\Constant\ColumnType; use Yiisoft\Db\Constant\PseudoType; use Yiisoft\Db\Pgsql\Column\ColumnDefinitionBuilder; @@ -50,14 +51,16 @@ final class QueryBuilder extends AbstractQueryBuilder PseudoType::UUID_PK => 'uuid PRIMARY KEY', ]; - public function __construct(QuoterInterface $quoter, SchemaInterface $schema) - { - $ddlBuilder = new DDLQueryBuilder($this, $quoter, $schema); - $dmlBuilder = new DMLQueryBuilder($this, $quoter, $schema); - $dqlBuilder = new DQLQueryBuilder($this, $quoter); - $columnDefinitionBuilder = new ColumnDefinitionBuilder($this); - - parent::__construct($quoter, $schema, $ddlBuilder, $dmlBuilder, $dqlBuilder, $columnDefinitionBuilder); + public function __construct(QuoterInterface $quoter, SchemaInterface $schema, ServerInfoInterface $serverInfo) { + parent::__construct( + $quoter, + $schema, + $serverInfo, + new DDLQueryBuilder($this, $quoter, $schema), + new DMLQueryBuilder($this, $quoter, $schema), + new DQLQueryBuilder($this, $quoter), + new ColumnDefinitionBuilder($this), + ); } protected function prepareBinary(string $binary): string diff --git a/src/Schema.php b/src/Schema.php index ad7a269ef..a2f6f1e73 100644 --- a/src/Schema.php +++ b/src/Schema.php @@ -611,7 +611,7 @@ protected function findColumns(TableSchemaInterface $table): bool { $orIdentity = ''; - if (version_compare($this->db->getServerVersion(), '12.0', '>=')) { + if (version_compare($this->db->getServerInfo()->getVersion(), '12.0', '>=')) { $orIdentity = 'OR a.attidentity != \'\''; } diff --git a/tests/QueryBuilderTest.php b/tests/QueryBuilderTest.php index a1c8e4856..acd6ce97c 100644 --- a/tests/QueryBuilderTest.php +++ b/tests/QueryBuilderTest.php @@ -583,7 +583,7 @@ public function testResetSequence(): void */ public function testResetSequencePgsql12(): void { - if (version_compare($this->getConnection()->getServerVersion(), '12.0', '<')) { + if (version_compare($this->getConnection()->getServerInfo()->getVersion(), '12.0', '<')) { $this->markTestSkipped('PostgreSQL < 12.0 does not support GENERATED AS IDENTITY columns.'); } diff --git a/tests/SchemaTest.php b/tests/SchemaTest.php index 07cf296c5..4c3762d28 100644 --- a/tests/SchemaTest.php +++ b/tests/SchemaTest.php @@ -65,7 +65,7 @@ public function testColumnSchema(array $columns, string $tableName): void { $db = $this->getConnection(); - if (version_compare($db->getServerVersion(), '10', '>')) { + if (version_compare($db->getServerInfo()->getVersion(), '10', '>')) { if ($tableName === 'type') { $columns['ts_default']['defaultValue'] = new Expression('CURRENT_TIMESTAMP'); } @@ -111,7 +111,7 @@ public function testGeneratedValues(): void { $this->fixture = 'pgsql12.sql'; - if (version_compare($this->getConnection()->getServerVersion(), '12.0', '<')) { + if (version_compare($this->getConnection()->getServerInfo()->getVersion(), '12.0', '<')) { $this->markTestSkipped('PostgresSQL < 12.0 does not support GENERATED AS IDENTITY columns.'); } @@ -251,7 +251,7 @@ public function testPartitionedTable(): void { $this->fixture = 'pgsql10.sql'; - if (version_compare($this->getConnection()->getServerVersion(), '10.0', '<')) { + if (version_compare($this->getConnection()->getServerInfo()->getVersion(), '10.0', '<')) { $this->markTestSkipped('PostgresSQL < 10.0 does not support PARTITION BY clause.'); } @@ -603,7 +603,7 @@ public function testTableIndexes(): void { $this->fixture = 'pgsql11.sql'; - if (version_compare($this->getConnection()->getServerVersion(), '11.0', '<')) { + if (version_compare($this->getConnection()->getServerInfo()->getVersion(), '11.0', '<')) { $this->markTestSkipped('PostgresSQL < 11.0 does not support INCLUDE clause.'); } From 2429c9233daf2268fede562ace3f673ecb9f62a0 Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Tue, 3 Dec 2024 08:05:43 +0000 Subject: [PATCH 2/3] Apply fixes from StyleCI --- src/QueryBuilder.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/QueryBuilder.php b/src/QueryBuilder.php index 8f65aea11..a8a9b21be 100644 --- a/src/QueryBuilder.php +++ b/src/QueryBuilder.php @@ -51,7 +51,8 @@ final class QueryBuilder extends AbstractQueryBuilder PseudoType::UUID_PK => 'uuid PRIMARY KEY', ]; - public function __construct(QuoterInterface $quoter, SchemaInterface $schema, ServerInfoInterface $serverInfo) { + public function __construct(QuoterInterface $quoter, SchemaInterface $schema, ServerInfoInterface $serverInfo) + { parent::__construct( $quoter, $schema, From 4cc40d5a67fc17c1b3f94795a670cf3e1ca5a1c9 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Sun, 8 Dec 2024 14:05:25 +0700 Subject: [PATCH 3/3] Add line to CHANGELOG.md [skip ci] --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7860c5aa3..1730fb3b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ - Enh #366: Use constructor to create columns and initialize properties (@Tigrov) - Enh #370: Refactor `Schema::normalizeDefaultValue()` method and move it to `ColumnFactory` class (@Tigrov) - New #373: Override `QueryBuilder::prepareBinary()` method (@Tigrov) +- Chg #375: Update `QueryBuilder` constructor (@Tigrov) ## 1.3.0 March 21, 2024