Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
- Chg #388: Change supported PHP versions to `8.1 - 8.4` (@Tigrov)
- Enh #388: Minor refactoring (@Tigrov)
- Chg #390: Remove `yiisoft/json` dependency (@Tigrov)
- Enh #393: Refactor according changes in `db` package (@Tigrov)
- New #391: Add `caseSensitive` option to like condition (@vjik)

## 1.3.0 March 21, 2024
Expand Down
2 changes: 0 additions & 2 deletions src/Builder/ArrayExpressionBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
$column = $this->getColumn($expression);
$dbType = $this->getColumnDbType($column);

$typeHint = $this->getTypeHint($dbType, $column?->getDimension() ?? 1);

Check warning on line 37 in src/Builder/ArrayExpressionBuilder.php

View workflow job for this annotation

GitHub Actions / PHP 8.4-ubuntu-latest

Escaped Mutant for Mutator "IncrementInteger": @@ @@ $param = new Param($value, DataType::STRING); $column = $this->getColumn($expression); $dbType = $this->getColumnDbType($column); - $typeHint = $this->getTypeHint($dbType, $column?->getDimension() ?? 1); + $typeHint = $this->getTypeHint($dbType, $column?->getDimension() ?? 2); return $this->queryBuilder->bindParam($param, $params) . $typeHint; } protected function buildSubquery(QueryInterface $query, ArrayExpression $expression, array &$params): string

Check warning on line 37 in src/Builder/ArrayExpressionBuilder.php

View workflow job for this annotation

GitHub Actions / PHP 8.4-ubuntu-latest

Escaped Mutant for Mutator "DecrementInteger": @@ @@ $param = new Param($value, DataType::STRING); $column = $this->getColumn($expression); $dbType = $this->getColumnDbType($column); - $typeHint = $this->getTypeHint($dbType, $column?->getDimension() ?? 1); + $typeHint = $this->getTypeHint($dbType, $column?->getDimension() ?? 0); return $this->queryBuilder->bindParam($param, $params) . $typeHint; } protected function buildSubquery(QueryInterface $query, ArrayExpression $expression, array &$params): string

return $this->queryBuilder->bindParam($param, $params) . $typeHint;
}
Expand Down Expand Up @@ -128,7 +128,6 @@
} elseif ($type !== ColumnType::ARRAY) {
$column = $this
->queryBuilder
->getSchema()
->getColumnFactory()
->fromDefinition($type);

Expand All @@ -142,7 +141,6 @@
/** @var AbstractArrayColumn */
return $this
->queryBuilder
->getSchema()
->getColumnFactory()
->fromType(ColumnType::ARRAY, $info);
}
Expand Down Expand Up @@ -183,7 +181,7 @@
}

if (!is_array($value)) {
$value = iterator_to_array($value, false);

Check warning on line 184 in src/Builder/ArrayExpressionBuilder.php

View workflow job for this annotation

GitHub Actions / PHP 8.4-ubuntu-latest

Escaped Mutant for Mutator "FalseValue": @@ @@ return $value; } if (!is_array($value)) { - $value = iterator_to_array($value, false); + $value = iterator_to_array($value, true); } return array_map($column->dbTypecast(...), $value); } }
}

return array_map($column->dbTypecast(...), $value);
Expand Down
25 changes: 10 additions & 15 deletions src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
use Yiisoft\Db\Driver\Pdo\AbstractPdoConnection;
use Yiisoft\Db\Driver\Pdo\PdoCommandInterface;
use Yiisoft\Db\Exception\InvalidArgumentException;
use Yiisoft\Db\Pgsql\Column\ColumnFactory;
use Yiisoft\Db\QueryBuilder\QueryBuilderInterface;
use Yiisoft\Db\Schema\Column\ColumnFactoryInterface;
use Yiisoft\Db\Schema\Quoter;
use Yiisoft\Db\Schema\QuoterInterface;
use Yiisoft\Db\Schema\SchemaInterface;
Expand All @@ -29,7 +31,7 @@
}

if ($this->logger !== null) {
$command->setLogger($this->logger);

Check warning on line 34 in src/Connection.php

View workflow job for this annotation

GitHub Actions / PHP 8.4-ubuntu-latest

Escaped Mutant for Mutator "MethodCallRemoval": @@ @@ $command->setSql($sql); } if ($this->logger !== null) { - $command->setLogger($this->logger); + } if ($this->profiler !== null) { $command->setProfiler($this->profiler);
}

if ($this->profiler !== null) {
Expand All @@ -44,6 +46,11 @@
return new Transaction($this);
}

public function getColumnFactory(): ColumnFactoryInterface
{
return new ColumnFactory();
}

public function getLastInsertID(?string $sequenceName = null): string
{
if ($sequenceName === null) {
Expand All @@ -55,28 +62,16 @@

public function getQueryBuilder(): QueryBuilderInterface
{
return $this->queryBuilder ??= new QueryBuilder(
$this->getQuoter(),
$this->getSchema(),
$this->getServerInfo(),
);
return $this->queryBuilder ??= new QueryBuilder($this);
}

public function getQuoter(): QuoterInterface
{
if ($this->quoter === null) {
$this->quoter = new Quoter('"', '"', $this->getTablePrefix());
}

return $this->quoter;
return $this->quoter ??= new Quoter('"', '"', $this->getTablePrefix());
}

public function getSchema(): SchemaInterface
{
if ($this->schema === null) {
$this->schema = new Schema($this, $this->schemaCache);
}

return $this->schema;
return $this->schema ??= new Schema($this, $this->schemaCache);
}
}
2 changes: 1 addition & 1 deletion src/DDLQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
return "ALTER TABLE $tableName ALTER COLUMN $columnName $type";
}

$type = $this->schema->getColumnFactory()->fromDefinition($type);
$type = $this->queryBuilder->getColumnFactory()->fromDefinition($type);
}

$columnDefinitionBuilder = $this->queryBuilder->getColumnDefinitionBuilder();
Expand Down Expand Up @@ -77,7 +77,7 @@
/**
* @throws Throwable
*/
public function checkIntegrity(string $schema = '', string $table = '', bool $check = true): string

Check warning on line 80 in src/DDLQueryBuilder.php

View workflow job for this annotation

GitHub Actions / PHP 8.4-ubuntu-latest

Escaped Mutant for Mutator "TrueValue": @@ @@ /** * @throws Throwable */ - public function checkIntegrity(string $schema = '', string $table = '', bool $check = true): string + public function checkIntegrity(string $schema = '', string $table = '', bool $check = false): string { /** @psalm-var Schema $schemaInstance */ $schemaInstance = $this->schema;
{
/** @psalm-var Schema $schemaInstance */
$schemaInstance = $this->schema;
Expand Down
13 changes: 6 additions & 7 deletions src/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@

namespace Yiisoft\Db\Pgsql;

use Yiisoft\Db\Connection\ServerInfoInterface;
use Yiisoft\Db\Connection\ConnectionInterface;
use Yiisoft\Db\Pgsql\Column\ColumnDefinitionBuilder;
use Yiisoft\Db\QueryBuilder\AbstractQueryBuilder;
use Yiisoft\Db\Schema\QuoterInterface;
use Yiisoft\Db\Schema\SchemaInterface;

use function bin2hex;

Expand All @@ -17,12 +15,13 @@
*/
final class QueryBuilder extends AbstractQueryBuilder
{
public function __construct(QuoterInterface $quoter, SchemaInterface $schema, ServerInfoInterface $serverInfo)
public function __construct(ConnectionInterface $db)
{
$quoter = $db->getQuoter();
$schema = $db->getSchema();

parent::__construct(
$quoter,
$schema,
$serverInfo,
$db,
new DDLQueryBuilder($this, $quoter, $schema),
new DMLQueryBuilder($this, $quoter, $schema),
new DQLQueryBuilder($this, $quoter),
Expand Down
9 changes: 1 addition & 8 deletions src/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
use Yiisoft\Db\Exception\InvalidConfigException;
use Yiisoft\Db\Exception\NotSupportedException;
use Yiisoft\Db\Helper\DbArrayHelper;
use Yiisoft\Db\Pgsql\Column\ColumnFactory;
use Yiisoft\Db\Pgsql\Column\SequenceColumnInterface;
use Yiisoft\Db\Schema\Column\ColumnFactoryInterface;
use Yiisoft\Db\Schema\Column\ColumnInterface;
use Yiisoft\Db\Schema\TableSchemaInterface;

Expand Down Expand Up @@ -94,11 +92,6 @@ final class Schema extends AbstractPdoSchema
*/
protected string|null $defaultSchema = 'public';

public function getColumnFactory(): ColumnFactoryInterface
{
return new ColumnFactory();
}

/**
* Resolves the table name and schema name (if any).
*
Expand Down Expand Up @@ -715,7 +708,7 @@ protected function findColumns(TableSchemaInterface $table): bool
*/
private function loadColumn(array $info): ColumnInterface
{
$columnFactory = $this->getColumnFactory();
$columnFactory = $this->db->getColumnFactory();
$dbType = $info['data_type'];

if (!in_array($info['type_scheme'], [$this->defaultSchema, 'pg_catalog'], true)) {
Expand Down
4 changes: 2 additions & 2 deletions tests/ColumnFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function testFromDbType(string $dbType, string $expectedType, string $exp
parent::testFromDbType($dbType, $expectedType, $expectedInstanceOf);

$db = $this->getConnection();
$columnFactory = $db->getSchema()->getColumnFactory();
$columnFactory = $db->getColumnFactory();

// For array type
$column = $columnFactory->fromType(ColumnType::ARRAY, ['dbType' => $dbType]);
Expand Down Expand Up @@ -56,7 +56,7 @@ public function testFromType(string $type, string $expectedType, string $expecte
parent::testFromType($type, $expectedType, $expectedInstanceOf);

$db = $this->getConnection();
$columnFactory = $db->getSchema()->getColumnFactory();
$columnFactory = $db->getColumnFactory();

// For array type
$column = $columnFactory->fromType(ColumnType::ARRAY, ['column' => $columnFactory->fromType($type)]);
Expand Down
10 changes: 10 additions & 0 deletions tests/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Yiisoft\Db\Exception\Exception;
use Yiisoft\Db\Exception\InvalidConfigException;
use Yiisoft\Db\Exception\NotSupportedException;
use Yiisoft\Db\Pgsql\Column\ColumnFactory;
use Yiisoft\Db\Pgsql\Tests\Support\TestTrait;
use Yiisoft\Db\Tests\Common\CommonConnectionTest;
use Yiisoft\Db\Transaction\TransactionInterface;
Expand Down Expand Up @@ -133,4 +134,13 @@ static function (ConnectionInterface $db) {

$db->close();
}

public function testGetColumnFactory(): void
{
$db = $this->getConnection();

$this->assertInstanceOf(ColumnFactory::class, $db->getColumnFactory());

$db->close();
}
}
10 changes: 0 additions & 10 deletions tests/SchemaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use Yiisoft\Db\Exception\InvalidConfigException;
use Yiisoft\Db\Exception\NotSupportedException;
use Yiisoft\Db\Expression\Expression;
use Yiisoft\Db\Pgsql\Column\ColumnFactory;
use Yiisoft\Db\Pgsql\Schema;
use Yiisoft\Db\Pgsql\Tests\Support\TestTrait;
use Yiisoft\Db\Schema\SchemaInterface;
Expand Down Expand Up @@ -637,13 +636,4 @@ public function testTableIndexes(): void

$db->close();
}

public function testGetColumnFactory(): void
{
$db = $this->getConnection();

$this->assertInstanceOf(ColumnFactory::class, $db->getSchema()->getColumnFactory());

$db->close();
}
}
Loading