Skip to content

Commit

Permalink
Merge branch 'refs/heads/master' into use-new-column-definition-builder
Browse files Browse the repository at this point in the history
  • Loading branch information
Tigrov committed Dec 8, 2024
2 parents 0166a64 + dddc3dc commit 498fb19
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 21 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
13 changes: 5 additions & 8 deletions src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 11 additions & 7 deletions src/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -50,14 +51,17 @@ final class QueryBuilder extends AbstractQueryBuilder
PseudoType::UUID_PK => 'uuid PRIMARY KEY',
];

public function __construct(QuoterInterface $quoter, SchemaInterface $schema)
public function __construct(QuoterInterface $quoter, SchemaInterface $schema, ServerInfoInterface $serverInfo)
{
$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);
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
Expand Down
2 changes: 1 addition & 1 deletion src/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,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 != \'\'';
}

Expand Down
2 changes: 1 addition & 1 deletion tests/QueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,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.');
}
Expand Down
8 changes: 4 additions & 4 deletions tests/SchemaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down Expand Up @@ -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.');
}

Expand Down Expand Up @@ -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.');
}

Expand Down Expand Up @@ -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.');
}

Expand Down

0 comments on commit 498fb19

Please sign in to comment.