Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New columns for v2 #808

Closed
wants to merge 28 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
a57729b
Column type classes
Tigrov Sep 1, 2023
a458258
Remove extra tests
Tigrov Sep 1, 2023
0ef31a1
Remove final
Tigrov Sep 1, 2023
eea7d04
Refactor tests
Tigrov Sep 1, 2023
3928a3e
Apply StyleCI fixes
Tigrov Sep 1, 2023
d029f8d
Merge branch 'master' into column_type_classes2
Tigrov Sep 1, 2023
83c6241
Improve params of `createColumnSchema()`
Tigrov Sep 3, 2023
f52b96f
Merge branch 'master' into column_type_classes2
Tigrov Sep 3, 2023
7b91caf
Remove a duplicate test
Tigrov Sep 5, 2023
4cca03b
Add line to CHANGELOG.md
Tigrov Sep 5, 2023
4231047
Merge remote-tracking branch 'origin/master' into column_type_classes2
Tigrov Oct 7, 2023
d7a46bb
Merge branch 'master' into column_type_classes2
Tigrov Jan 18, 2024
b39d637
Improve
Tigrov Jan 29, 2024
37249b9
New columns for v2
Tigrov Feb 7, 2024
b65717b
Apply fixes from StyleCI
StyleCIBot Feb 7, 2024
327acf5
Merge branch 'refs/heads/master' into column_type_classes2
Tigrov Apr 20, 2024
330b2a3
Remove `$quoter` property from `ColumnDefinitionBuilder`
Tigrov Apr 20, 2024
524c7a9
Improve typecasting
Tigrov Apr 21, 2024
7949d64
Improve `Column` class and interface
Tigrov Apr 21, 2024
dadc56c
Improve `ColumnBuilder` class
Tigrov Apr 21, 2024
dce4725
Update tests + fix
Tigrov Apr 21, 2024
4e73b9c
Refactor `ColumnFactory`
Tigrov Apr 21, 2024
9f15381
Remove types bit, array, composite
Tigrov Apr 21, 2024
88e3c72
Improve code and tests
Tigrov Apr 22, 2024
40b0676
Merge branch 'refs/heads/master' into new-columns-for-v2
Tigrov Apr 22, 2024
8831997
Merge branch 'refs/heads/column_type_classes2' into new-columns-for-v2
Tigrov Apr 22, 2024
8adb44e
Remove extra code
Tigrov Apr 22, 2024
5510e4f
Apply fixes from StyleCI
StyleCIBot Apr 22, 2024
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@
- Bug #746: Typecast values in `AbstractDMLQueryBuilder::batchInsert()` if column names with table name and brackets (@Tigrov)
- Bug #746, #61: Typecast values in `AbstractDMLQueryBuilder::batchInsert()` if values with string keys (@Tigrov)
- Bug #751: Fix collected debug actions (@xepozz)
- Enh #752: Implement `ColumnSchemaInterface` classes according to the data type of database table columns
for type casting performance (@Tigrov)
- Chg #755: Deprecate `TableSchemaInterface::compositeForeignKey()` (@Tigrov)
- Enh #756: Refactor `Quoter` (@Tigrov)
- Bug #756: Fix `Quoter::quoteSql()` for SQL containing table with prefix (@Tigrov)
- Bug #756: Fix `Quoter::getTableNameParts()` for cases when different quotes for tables and columns (@Tigrov)
- Bug #756: Fix `Quoter::quoteTableName()` for sub-query with alias (@Tigrov)
- Bug #761: Quote aliases of CTE in `WITH` queries (@Tigrov)
- Bug #769, #61: Fix `AbstractDMLQueryBuilder::batchInsert()` for values as associative arrays (@Tigrov)
Expand Down
2 changes: 1 addition & 1 deletion src/Command/AbstractCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use Yiisoft\Db\Query\Data\DataReaderInterface;
use Yiisoft\Db\Query\QueryInterface;
use Yiisoft\Db\QueryBuilder\QueryBuilderInterface;
use Yiisoft\Db\Schema\Builder\ColumnInterface;
use Yiisoft\Db\Schema\Column\ColumnInterface;

use function explode;
use function get_resource_type;
Expand Down
2 changes: 1 addition & 1 deletion src/Command/CommandInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use Yiisoft\Db\Exception\NotSupportedException;
use Yiisoft\Db\Query\Data\DataReaderInterface;
use Yiisoft\Db\Query\QueryInterface;
use Yiisoft\Db\Schema\Builder\ColumnInterface;
use Yiisoft\Db\Schema\Column\ColumnInterface;

/**
* This interface represents a database command, such as a `SELECT`, `INSERT`, `UPDATE`, or `DELETE` statement.
Expand All @@ -42,7 +42,7 @@
*
* @param string $table The name of the table to add new column to.
* @param string $column The name of the new column.
* @param ColumnInterface|string $type The column type. {@see QueryBuilder::getColumnType()} will be called

Check failure on line 45 in src/Command/CommandInterface.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.3-ubuntu-latest

MismatchingDocblockParamType

src/Command/CommandInterface.php:45:15: MismatchingDocblockParamType: Parameter $type has wrong type 'Yiisoft\Db\Schema\Column\ColumnInterface|string', should be 'Yiisoft\Db\Schema\Builder\ColumnInterface|string' (see https://psalm.dev/141)

Check failure on line 45 in src/Command/CommandInterface.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.3-ubuntu-latest

DeprecatedInterface

src/Command/CommandInterface.php:45:15: DeprecatedInterface: Interface Yiisoft\Db\Schema\Builder\ColumnInterface is marked as deprecated (see https://psalm.dev/152)

Check failure on line 45 in src/Command/CommandInterface.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.2-ubuntu-latest

MismatchingDocblockParamType

src/Command/CommandInterface.php:45:15: MismatchingDocblockParamType: Parameter $type has wrong type 'Yiisoft\Db\Schema\Column\ColumnInterface|string', should be 'Yiisoft\Db\Schema\Builder\ColumnInterface|string' (see https://psalm.dev/141)

Check failure on line 45 in src/Command/CommandInterface.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.2-ubuntu-latest

DeprecatedInterface

src/Command/CommandInterface.php:45:15: DeprecatedInterface: Interface Yiisoft\Db\Schema\Builder\ColumnInterface is marked as deprecated (see https://psalm.dev/152)

Check failure on line 45 in src/Command/CommandInterface.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.2-ubuntu-latest

MismatchingDocblockParamType

src/Command/CommandInterface.php:45:15: MismatchingDocblockParamType: Parameter $type has wrong type 'Yiisoft\Db\Schema\Column\ColumnInterface|string', should be 'Yiisoft\Db\Schema\Builder\ColumnInterface|string' (see https://psalm.dev/141)

Check failure on line 45 in src/Command/CommandInterface.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.2-ubuntu-latest

DeprecatedInterface

src/Command/CommandInterface.php:45:15: DeprecatedInterface: Interface Yiisoft\Db\Schema\Builder\ColumnInterface is marked as deprecated (see https://psalm.dev/152)

Check failure on line 45 in src/Command/CommandInterface.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.3-ubuntu-latest

MismatchingDocblockParamType

src/Command/CommandInterface.php:45:15: MismatchingDocblockParamType: Parameter $type has wrong type 'Yiisoft\Db\Schema\Column\ColumnInterface|string', should be 'Yiisoft\Db\Schema\Builder\ColumnInterface|string' (see https://psalm.dev/141)

Check failure on line 45 in src/Command/CommandInterface.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.3-ubuntu-latest

DeprecatedInterface

src/Command/CommandInterface.php:45:15: DeprecatedInterface: Interface Yiisoft\Db\Schema\Builder\ColumnInterface is marked as deprecated (see https://psalm.dev/152)

Check failure on line 45 in src/Command/CommandInterface.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.1-ubuntu-latest

MismatchingDocblockParamType

src/Command/CommandInterface.php:45:15: MismatchingDocblockParamType: Parameter $type has wrong type 'Yiisoft\Db\Schema\Column\ColumnInterface|string', should be 'Yiisoft\Db\Schema\Builder\ColumnInterface|string' (see https://psalm.dev/141)

Check failure on line 45 in src/Command/CommandInterface.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.1-ubuntu-latest

DeprecatedInterface

src/Command/CommandInterface.php:45:15: DeprecatedInterface: Interface Yiisoft\Db\Schema\Builder\ColumnInterface is marked as deprecated (see https://psalm.dev/152)

Check failure on line 45 in src/Command/CommandInterface.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.1-ubuntu-latest

MismatchingDocblockParamType

src/Command/CommandInterface.php:45:15: MismatchingDocblockParamType: Parameter $type has wrong type 'Yiisoft\Db\Schema\Column\ColumnInterface|string', should be 'Yiisoft\Db\Schema\Builder\ColumnInterface|string' (see https://psalm.dev/141)

Check failure on line 45 in src/Command/CommandInterface.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.1-ubuntu-latest

DeprecatedInterface

src/Command/CommandInterface.php:45:15: DeprecatedInterface: Interface Yiisoft\Db\Schema\Builder\ColumnInterface is marked as deprecated (see https://psalm.dev/152)
* to convert the given column type to the database one.
* For example, `string` will be converted to `varchar(255)`, and `string not null` becomes `varchar(255) not null`.
*
Expand Down Expand Up @@ -142,7 +142,7 @@
*
* @param string $table The table whose column is to change.
* @param string $column The name of the column to change.
* @param ColumnInterface|string $type The column type. {@see QueryBuilder::getColumnType()} will be called to

Check failure on line 145 in src/Command/CommandInterface.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.3-ubuntu-latest

MismatchingDocblockParamType

src/Command/CommandInterface.php:145:15: MismatchingDocblockParamType: Parameter $type has wrong type 'Yiisoft\Db\Schema\Column\ColumnInterface|string', should be 'Yiisoft\Db\Schema\Builder\ColumnInterface|string' (see https://psalm.dev/141)

Check failure on line 145 in src/Command/CommandInterface.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.3-ubuntu-latest

DeprecatedInterface

src/Command/CommandInterface.php:145:15: DeprecatedInterface: Interface Yiisoft\Db\Schema\Builder\ColumnInterface is marked as deprecated (see https://psalm.dev/152)

Check failure on line 145 in src/Command/CommandInterface.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.2-ubuntu-latest

MismatchingDocblockParamType

src/Command/CommandInterface.php:145:15: MismatchingDocblockParamType: Parameter $type has wrong type 'Yiisoft\Db\Schema\Column\ColumnInterface|string', should be 'Yiisoft\Db\Schema\Builder\ColumnInterface|string' (see https://psalm.dev/141)

Check failure on line 145 in src/Command/CommandInterface.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.2-ubuntu-latest

DeprecatedInterface

src/Command/CommandInterface.php:145:15: DeprecatedInterface: Interface Yiisoft\Db\Schema\Builder\ColumnInterface is marked as deprecated (see https://psalm.dev/152)

Check failure on line 145 in src/Command/CommandInterface.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.2-ubuntu-latest

MismatchingDocblockParamType

src/Command/CommandInterface.php:145:15: MismatchingDocblockParamType: Parameter $type has wrong type 'Yiisoft\Db\Schema\Column\ColumnInterface|string', should be 'Yiisoft\Db\Schema\Builder\ColumnInterface|string' (see https://psalm.dev/141)

Check failure on line 145 in src/Command/CommandInterface.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.2-ubuntu-latest

DeprecatedInterface

src/Command/CommandInterface.php:145:15: DeprecatedInterface: Interface Yiisoft\Db\Schema\Builder\ColumnInterface is marked as deprecated (see https://psalm.dev/152)

Check failure on line 145 in src/Command/CommandInterface.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.3-ubuntu-latest

MismatchingDocblockParamType

src/Command/CommandInterface.php:145:15: MismatchingDocblockParamType: Parameter $type has wrong type 'Yiisoft\Db\Schema\Column\ColumnInterface|string', should be 'Yiisoft\Db\Schema\Builder\ColumnInterface|string' (see https://psalm.dev/141)

Check failure on line 145 in src/Command/CommandInterface.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.3-ubuntu-latest

DeprecatedInterface

src/Command/CommandInterface.php:145:15: DeprecatedInterface: Interface Yiisoft\Db\Schema\Builder\ColumnInterface is marked as deprecated (see https://psalm.dev/152)

Check failure on line 145 in src/Command/CommandInterface.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.1-ubuntu-latest

MismatchingDocblockParamType

src/Command/CommandInterface.php:145:15: MismatchingDocblockParamType: Parameter $type has wrong type 'Yiisoft\Db\Schema\Column\ColumnInterface|string', should be 'Yiisoft\Db\Schema\Builder\ColumnInterface|string' (see https://psalm.dev/141)

Check failure on line 145 in src/Command/CommandInterface.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.1-ubuntu-latest

DeprecatedInterface

src/Command/CommandInterface.php:145:15: DeprecatedInterface: Interface Yiisoft\Db\Schema\Builder\ColumnInterface is marked as deprecated (see https://psalm.dev/152)

Check failure on line 145 in src/Command/CommandInterface.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.1-ubuntu-latest

MismatchingDocblockParamType

src/Command/CommandInterface.php:145:15: MismatchingDocblockParamType: Parameter $type has wrong type 'Yiisoft\Db\Schema\Column\ColumnInterface|string', should be 'Yiisoft\Db\Schema\Builder\ColumnInterface|string' (see https://psalm.dev/141)

Check failure on line 145 in src/Command/CommandInterface.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.1-ubuntu-latest

DeprecatedInterface

src/Command/CommandInterface.php:145:15: DeprecatedInterface: Interface Yiisoft\Db\Schema\Builder\ColumnInterface is marked as deprecated (see https://psalm.dev/152)
* convert the give column type to the physical one. For example, `string` will be converted as `varchar(255)`, and
* `string not null` becomes `varchar(255) not null`.
*
Expand Down
10 changes: 6 additions & 4 deletions src/Driver/Pdo/AbstractPdoConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
use Yiisoft\Db\Profiler\ProfilerAwareInterface;
use Yiisoft\Db\Profiler\ProfilerAwareTrait;
use Yiisoft\Db\QueryBuilder\QueryBuilderInterface;
use Yiisoft\Db\Schema\Column\ColumnFactoryInterface;
use Yiisoft\Db\Schema\QuoterInterface;
use Yiisoft\Db\Schema\SchemaInterface;
use Yiisoft\Db\Transaction\TransactionInterface;

use function array_keys;
Expand All @@ -47,10 +47,12 @@ abstract class AbstractPdoConnection extends AbstractConnection implements PdoCo
protected bool|null $emulatePrepare = null;
protected QueryBuilderInterface|null $queryBuilder = null;
protected QuoterInterface|null $quoter = null;
protected SchemaInterface|null $schema = null;

public function __construct(protected PdoDriverInterface $driver, protected SchemaCache $schemaCache)
{
public function __construct(
protected PdoDriverInterface $driver,
protected SchemaCache $schemaCache,
protected ColumnFactoryInterface|null $columnFactory = null,
) {
}

/**
Expand Down
9 changes: 4 additions & 5 deletions src/QueryBuilder/AbstractDDLQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Yiisoft\Db\Exception\NotSupportedException;
use Yiisoft\Db\Query\QueryInterface;
use Yiisoft\Db\Schema\Builder\ColumnInterface;
use Yiisoft\Db\Schema\Column\ColumnInterface;
use Yiisoft\Db\Schema\QuoterInterface;
use Yiisoft\Db\Schema\SchemaInterface;

Expand Down Expand Up @@ -46,7 +46,7 @@
. ' ADD '
. $this->quoter->quoteColumnName($column)
. ' '
. $this->queryBuilder->getColumnType($type);
. $this->queryBuilder->buildColumnDefinition($type);

Check failure on line 49 in src/QueryBuilder/AbstractDDLQueryBuilder.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.3-ubuntu-latest

PossiblyInvalidArgument

src/QueryBuilder/AbstractDDLQueryBuilder.php:49:58: PossiblyInvalidArgument: Argument 1 of Yiisoft\Db\QueryBuilder\QueryBuilderInterface::buildColumnDefinition expects Yiisoft\Db\Schema\Column\ColumnInterface, but possibly different type Yiisoft\Db\Schema\Column\ColumnInterface|string provided (see https://psalm.dev/092)

Check failure on line 49 in src/QueryBuilder/AbstractDDLQueryBuilder.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.2-ubuntu-latest

PossiblyInvalidArgument

src/QueryBuilder/AbstractDDLQueryBuilder.php:49:58: PossiblyInvalidArgument: Argument 1 of Yiisoft\Db\QueryBuilder\QueryBuilderInterface::buildColumnDefinition expects Yiisoft\Db\Schema\Column\ColumnInterface, but possibly different type Yiisoft\Db\Schema\Column\ColumnInterface|string provided (see https://psalm.dev/092)

Check failure on line 49 in src/QueryBuilder/AbstractDDLQueryBuilder.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.2-ubuntu-latest

PossiblyInvalidArgument

src/QueryBuilder/AbstractDDLQueryBuilder.php:49:58: PossiblyInvalidArgument: Argument 1 of Yiisoft\Db\QueryBuilder\QueryBuilderInterface::buildColumnDefinition expects Yiisoft\Db\Schema\Column\ColumnInterface, but possibly different type Yiisoft\Db\Schema\Column\ColumnInterface|string provided (see https://psalm.dev/092)

Check failure on line 49 in src/QueryBuilder/AbstractDDLQueryBuilder.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.3-ubuntu-latest

PossiblyInvalidArgument

src/QueryBuilder/AbstractDDLQueryBuilder.php:49:58: PossiblyInvalidArgument: Argument 1 of Yiisoft\Db\QueryBuilder\QueryBuilderInterface::buildColumnDefinition expects Yiisoft\Db\Schema\Column\ColumnInterface, but possibly different type Yiisoft\Db\Schema\Column\ColumnInterface|string provided (see https://psalm.dev/092)

Check failure on line 49 in src/QueryBuilder/AbstractDDLQueryBuilder.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.1-ubuntu-latest

PossiblyInvalidArgument

src/QueryBuilder/AbstractDDLQueryBuilder.php:49:58: PossiblyInvalidArgument: Argument 1 of Yiisoft\Db\QueryBuilder\QueryBuilderInterface::buildColumnDefinition expects Yiisoft\Db\Schema\Column\ColumnInterface, but possibly different type Yiisoft\Db\Schema\Column\ColumnInterface|string provided (see https://psalm.dev/092)

Check failure on line 49 in src/QueryBuilder/AbstractDDLQueryBuilder.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.1-ubuntu-latest

PossiblyInvalidArgument

src/QueryBuilder/AbstractDDLQueryBuilder.php:49:58: PossiblyInvalidArgument: Argument 1 of Yiisoft\Db\QueryBuilder\QueryBuilderInterface::buildColumnDefinition expects Yiisoft\Db\Schema\Column\ColumnInterface, but possibly different type Yiisoft\Db\Schema\Column\ColumnInterface|string provided (see https://psalm.dev/092)
}

public function addCommentOnColumn(string $table, string $column, string $comment): string
Expand Down Expand Up @@ -144,7 +144,7 @@
. $this->quoter->quoteColumnName($column)
. ' '
. $this->quoter->quoteColumnName($column) . ' '
. $this->queryBuilder->getColumnType($type);
. $this->queryBuilder->buildColumnDefinition($type);

Check failure on line 147 in src/QueryBuilder/AbstractDDLQueryBuilder.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.3-ubuntu-latest

PossiblyInvalidArgument

src/QueryBuilder/AbstractDDLQueryBuilder.php:147:58: PossiblyInvalidArgument: Argument 1 of Yiisoft\Db\QueryBuilder\QueryBuilderInterface::buildColumnDefinition expects Yiisoft\Db\Schema\Column\ColumnInterface, but possibly different type Yiisoft\Db\Schema\Column\ColumnInterface|string provided (see https://psalm.dev/092)

Check failure on line 147 in src/QueryBuilder/AbstractDDLQueryBuilder.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.2-ubuntu-latest

PossiblyInvalidArgument

src/QueryBuilder/AbstractDDLQueryBuilder.php:147:58: PossiblyInvalidArgument: Argument 1 of Yiisoft\Db\QueryBuilder\QueryBuilderInterface::buildColumnDefinition expects Yiisoft\Db\Schema\Column\ColumnInterface, but possibly different type Yiisoft\Db\Schema\Column\ColumnInterface|string provided (see https://psalm.dev/092)

Check failure on line 147 in src/QueryBuilder/AbstractDDLQueryBuilder.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.2-ubuntu-latest

PossiblyInvalidArgument

src/QueryBuilder/AbstractDDLQueryBuilder.php:147:58: PossiblyInvalidArgument: Argument 1 of Yiisoft\Db\QueryBuilder\QueryBuilderInterface::buildColumnDefinition expects Yiisoft\Db\Schema\Column\ColumnInterface, but possibly different type Yiisoft\Db\Schema\Column\ColumnInterface|string provided (see https://psalm.dev/092)

Check failure on line 147 in src/QueryBuilder/AbstractDDLQueryBuilder.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.3-ubuntu-latest

PossiblyInvalidArgument

src/QueryBuilder/AbstractDDLQueryBuilder.php:147:58: PossiblyInvalidArgument: Argument 1 of Yiisoft\Db\QueryBuilder\QueryBuilderInterface::buildColumnDefinition expects Yiisoft\Db\Schema\Column\ColumnInterface, but possibly different type Yiisoft\Db\Schema\Column\ColumnInterface|string provided (see https://psalm.dev/092)

Check failure on line 147 in src/QueryBuilder/AbstractDDLQueryBuilder.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.1-ubuntu-latest

PossiblyInvalidArgument

src/QueryBuilder/AbstractDDLQueryBuilder.php:147:58: PossiblyInvalidArgument: Argument 1 of Yiisoft\Db\QueryBuilder\QueryBuilderInterface::buildColumnDefinition expects Yiisoft\Db\Schema\Column\ColumnInterface, but possibly different type Yiisoft\Db\Schema\Column\ColumnInterface|string provided (see https://psalm.dev/092)

Check failure on line 147 in src/QueryBuilder/AbstractDDLQueryBuilder.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.1-ubuntu-latest

PossiblyInvalidArgument

src/QueryBuilder/AbstractDDLQueryBuilder.php:147:58: PossiblyInvalidArgument: Argument 1 of Yiisoft\Db\QueryBuilder\QueryBuilderInterface::buildColumnDefinition expects Yiisoft\Db\Schema\Column\ColumnInterface, but possibly different type Yiisoft\Db\Schema\Column\ColumnInterface|string provided (see https://psalm.dev/092)
}

public function checkIntegrity(string $schema = '', string $table = '', bool $check = true): string
Expand Down Expand Up @@ -174,9 +174,8 @@
$cols[] = "\t"
. $this->quoter->quoteColumnName($name)
. ' '
. $this->queryBuilder->getColumnType($type);
. $this->queryBuilder->buildColumnDefinition($type);
} else {
/** @psalm-var string $type */
$cols[] = "\t" . $type;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/QueryBuilder/AbstractDMLQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use Yiisoft\Db\Exception\NotSupportedException;
use Yiisoft\Db\Expression\ExpressionInterface;
use Yiisoft\Db\Query\QueryInterface;
use Yiisoft\Db\Schema\ColumnSchemaInterface;
use Yiisoft\Db\Schema\Column\ColumnInterface;
use Yiisoft\Db\Schema\QuoterInterface;
use Yiisoft\Db\Schema\SchemaInterface;

Expand Down Expand Up @@ -470,7 +470,7 @@
*
* @deprecated will be removed in version 2.0.0
*/
protected function getTypecastValue(mixed $value, ColumnSchemaInterface $columnSchema = null): mixed
protected function getTypecastValue(mixed $value, ColumnInterface $columnSchema = null): mixed

Check warning on line 473 in src/QueryBuilder/AbstractDMLQueryBuilder.php

View check run for this annotation

Codecov / codecov/patch

src/QueryBuilder/AbstractDMLQueryBuilder.php#L473

Added line #L473 was not covered by tests
{
if ($columnSchema) {
return $columnSchema->dbTypecast($value);
Expand Down
41 changes: 14 additions & 27 deletions src/QueryBuilder/AbstractQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@
use Yiisoft\Db\Expression\ExpressionInterface;
use Yiisoft\Db\Query\QueryInterface;
use Yiisoft\Db\QueryBuilder\Condition\Interface\ConditionInterface;
use Yiisoft\Db\Schema\Builder\ColumnInterface;
use Yiisoft\Db\Schema\Column\ColumnInterface;
use Yiisoft\Db\Schema\QuoterInterface;
use Yiisoft\Db\Schema\SchemaInterface;

use function count;
use function preg_match;
use function preg_replace;

/**
* Builds a SELECT SQL statement based on the specification given as a {@see QueryInterface} object.
Expand Down Expand Up @@ -44,7 +42,8 @@ public function __construct(
private SchemaInterface $schema,
private AbstractDDLQueryBuilder $ddlBuilder,
private AbstractDMLQueryBuilder $dmlBuilder,
private AbstractDQLQueryBuilder $dqlBuilder
private AbstractDQLQueryBuilder $dqlBuilder,
private ColumnDefinitionBuilder $columnDefinitionBuilder,
) {
}

Expand Down Expand Up @@ -305,31 +304,10 @@ public function dropView(string $viewName): string
return $this->ddlBuilder->dropView($viewName);
}

/** @deprecated Use {@see buildColumnDefinition()}. Will be removed in version 3.0.0. */
public function getColumnType(ColumnInterface|string $type): string
{
if ($type instanceof ColumnInterface) {
$type = $type->asString();
}

if (isset($this->typeMap[$type])) {
return $this->typeMap[$type];
}

if (preg_match('/^(\w+)\((.+?)\)(.*)$/', $type, $matches)) {
if (isset($this->typeMap[$matches[1]])) {
return preg_replace(
'/\(.+\)/',
'(' . $matches[2] . ')',
$this->typeMap[$matches[1]]
) . $matches[3];
}
} elseif (preg_match('/^(\w+)\s+/', $type, $matches)) {
if (isset($this->typeMap[$matches[1]])) {
return preg_replace('/^\w+/', $this->typeMap[$matches[1]], $type);
}
}

return $type;
return $this->buildColumnDefinition($type);
}

public function getExpressionBuilder(ExpressionInterface $expression): object
Expand Down Expand Up @@ -405,4 +383,13 @@ public function upsert(
): string {
return $this->dmlBuilder->upsert($table, $insertColumns, $updateColumns, $params);
}

public function buildColumnDefinition(ColumnInterface|string $column): string
{
if (!$column instanceof ColumnInterface) {
$column = $this->schema->getColumnFactory()->fromDefinition($column);
}

return $this->columnDefinitionBuilder->build($column);
}
}
Loading
Loading