diff --git a/CHANGELOG.md b/CHANGELOG.md index b1ae5016..855bdcb3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,16 +3,19 @@ ## 2.0.0 under development - Enh #289: Implement `SqlParser` and `ExpressionBuilder` driver classes (@Tigrov) -- Enh #273: Implement `ColumnSchemaInterface` classes according to the data type of database table columns +- New #273: Implement `ColumnSchemaInterface` classes according to the data type of database table columns for type casting performance. Related with yiisoft/db#752 (@Tigrov) - Chg #307: Replace call of `SchemaInterface::getRawTableName()` to `QuoterInterface::getRawTableName()` (@Tigrov) -- Enh #310: Add JSON overlaps condition builder (@Tigrov) +- New #310: Add JSON overlaps condition builder (@Tigrov) - Enh #312: Update `bit` type according to main PR yiisoft/db#860 (@Tigrov) - Enh #315: Raise minimum PHP version to `^8.1` with minor refactoring (@Tigrov) -- Enh #314: Implement `ColumnFactory` class (@Tigrov) +- New #314: Implement `ColumnFactory` class (@Tigrov) - Enh #317: Separate column type constants (@Tigrov) - Enh #318: Realize `ColumnBuilder` class (@Tigrov) - Enh #319: Set more specific result type in `Connection::createCommand()` method (@vjik) +- Enh #320: Update according changes in `ColumnSchemaInterface` (@Tigrov) +- New #322: Add `ColumnDefinitionBuilder` class (@Tigrov) +- Enh #323: Refactor `Dsn` class (@Tigrov) ## 1.2.0 March 21, 2024 diff --git a/src/Column/ColumnDefinitionBuilder.php b/src/Column/ColumnDefinitionBuilder.php new file mode 100644 index 00000000..b0534999 --- /dev/null +++ b/src/Column/ColumnDefinitionBuilder.php @@ -0,0 +1,100 @@ +buildType($column) + . $this->buildPrimaryKey($column) + . $this->buildAutoIncrement($column) + . $this->buildUnique($column) + . $this->buildNotNull($column) + . $this->buildDefault($column) + . $this->buildCheck($column) + . $this->buildReferences($column) + . $this->buildExtra($column) + . $this->buildComment($column); + } + + protected function buildComment(ColumnSchemaInterface $column): string + { + $comment = $column->getComment(); + + return $comment === null || $comment === '' ? '' : ' /* ' . str_replace('*/', '*\/', $comment) . ' */'; + } + + protected function buildNotNull(ColumnSchemaInterface $column): string + { + return $column->isPrimaryKey() ? ' NOT NULL' : parent::buildNotNull($column); + } + + protected function getDbType(ColumnSchemaInterface $column): string + { + /** @psalm-suppress DocblockTypeContradiction */ + return match ($column->getType()) { + ColumnType::BOOLEAN => 'boolean', + ColumnType::BIT => 'bit', + ColumnType::TINYINT => $column->isAutoIncrement() ? 'integer' : 'tinyint', + ColumnType::SMALLINT => $column->isAutoIncrement() ? 'integer' : 'smallint', + ColumnType::INTEGER => 'integer', + ColumnType::BIGINT => $column->isAutoIncrement() ? 'integer' : 'bigint', + ColumnType::FLOAT => 'float', + ColumnType::DOUBLE => 'double', + ColumnType::DECIMAL => 'decimal', + ColumnType::MONEY => 'decimal', + ColumnType::CHAR => 'char', + ColumnType::STRING => 'varchar', + ColumnType::TEXT => 'text', + ColumnType::BINARY => 'blob', + ColumnType::UUID => 'blob(16)', + ColumnType::DATETIME => 'datetime', + ColumnType::TIMESTAMP => 'timestamp', + ColumnType::DATE => 'date', + ColumnType::TIME => 'time', + ColumnType::ARRAY => 'json', + ColumnType::STRUCTURED => 'json', + ColumnType::JSON => 'json', + default => 'varchar', + }; + } +} diff --git a/src/Column/ColumnFactory.php b/src/Column/ColumnFactory.php index 42f40eb1..6c428d78 100644 --- a/src/Column/ColumnFactory.php +++ b/src/Column/ColumnFactory.php @@ -33,7 +33,6 @@ final class ColumnFactory extends AbstractColumnFactory 'numeric' => ColumnType::DECIMAL, 'char' => ColumnType::CHAR, 'varchar' => ColumnType::STRING, - 'string' => ColumnType::STRING, 'enum' => ColumnType::STRING, 'tinytext' => ColumnType::TEXT, 'mediumtext' => ColumnType::TEXT, diff --git a/src/Connection.php b/src/Connection.php index fea019ee..24bad653 100644 --- a/src/Connection.php +++ b/src/Connection.php @@ -6,11 +6,9 @@ use Yiisoft\Db\Driver\Pdo\AbstractPdoConnection; 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; -use Yiisoft\Db\Sqlite\Column\ColumnFactory; use Yiisoft\Db\Transaction\TransactionInterface; use function str_starts_with; @@ -71,11 +69,6 @@ public function getQueryBuilder(): QueryBuilderInterface return $this->queryBuilder; } - public function getColumnFactory(): ColumnFactoryInterface - { - return new ColumnFactory(); - } - public function getQuoter(): QuoterInterface { if ($this->quoter === null) { diff --git a/src/Dsn.php b/src/Dsn.php index 8806397a..8f8c356e 100644 --- a/src/Dsn.php +++ b/src/Dsn.php @@ -13,10 +13,7 @@ */ final class Dsn extends AbstractDsn { - /** - * @psalm-param string[] $options - */ - public function __construct(private string $driver, private string|null $databaseName = null) + public function __construct(string $driver = 'sqlite', string|null $databaseName = null) { parent::__construct($driver, '', $databaseName); } @@ -39,11 +36,14 @@ public function __construct(private string $driver, private string|null $databas */ public function asString(): string { - return match ($this->databaseName) { - '' => $this->driver . ':', - 'memory' => $this->driver . '::memory:', - null => $this->driver . ':', - default => $this->driver . ':' . $this->databaseName, + $driver = $this->getDriver(); + $databaseName = $this->getDatabaseName(); + + return match ($databaseName) { + '' => "$driver:", + null => "$driver:", + 'memory' => "$driver::memory:", + default => "$driver:$databaseName", }; } } diff --git a/src/QueryBuilder.php b/src/QueryBuilder.php index 1b255808..d8611802 100644 --- a/src/QueryBuilder.php +++ b/src/QueryBuilder.php @@ -9,6 +9,7 @@ use Yiisoft\Db\QueryBuilder\AbstractQueryBuilder; use Yiisoft\Db\Schema\QuoterInterface; use Yiisoft\Db\Schema\SchemaInterface; +use Yiisoft\Db\Sqlite\Column\ColumnDefinitionBuilder; /** * Implements the SQLite Server specific query builder. @@ -50,6 +51,8 @@ public function __construct(QuoterInterface $quoter, SchemaInterface $schema) $ddlBuilder = new DDLQueryBuilder($this, $quoter, $schema); $dmlBuilder = new DMLQueryBuilder($this, $quoter, $schema); $dqlBuilder = new DQLQueryBuilder($this, $quoter); - parent::__construct($quoter, $schema, $ddlBuilder, $dmlBuilder, $dqlBuilder); + $columnDefinitionBuilder = new ColumnDefinitionBuilder($this); + + parent::__construct($quoter, $schema, $ddlBuilder, $dmlBuilder, $dqlBuilder, $columnDefinitionBuilder); } } diff --git a/src/Schema.php b/src/Schema.php index 67752a2a..6ed3be62 100644 --- a/src/Schema.php +++ b/src/Schema.php @@ -18,8 +18,11 @@ use Yiisoft\Db\Expression\Expression; use Yiisoft\Db\Helper\DbArrayHelper; use Yiisoft\Db\Schema\Builder\ColumnInterface; +use Yiisoft\Db\Schema\Column\ColumnFactoryInterface; use Yiisoft\Db\Schema\Column\ColumnSchemaInterface; use Yiisoft\Db\Schema\TableSchemaInterface; +use Yiisoft\Db\Sqlite\Column\ColumnBuilder; +use Yiisoft\Db\Sqlite\Column\ColumnFactory; use function array_change_key_case; use function array_column; @@ -68,17 +71,22 @@ * dflt_value:string|null, * pk:string, * size?: int, - * precision?: int, * scale?: int, * } */ final class Schema extends AbstractPdoSchema { + /** @deprecated Use {@see ColumnBuilder} instead. Will be removed in 2.0. */ public function createColumn(string $type, array|int|string $length = null): ColumnInterface { return new Column($type, $length); } + public function getColumnFactory(): ColumnFactoryInterface + { + return new ColumnFactory(); + } + /** * Returns all table names in the database. * @@ -346,7 +354,7 @@ protected function findColumns(TableSchemaInterface $table): bool if ($column !== null && !strncasecmp($column->getDbType() ?? '', 'int', 3)) { $table->sequenceName(''); - $column->autoIncrement(true); + $column->autoIncrement(); } return !empty($columns); @@ -438,12 +446,12 @@ public function getSchemaDefaultValues(string $schema = '', bool $refresh = fals */ private function loadColumnSchema(array $info): ColumnSchemaInterface { - $columnFactory = $this->db->getColumnFactory(); + $columnFactory = $this->getColumnFactory(); $dbType = strtolower($info['type']); $column = $columnFactory->fromDefinition($dbType, ['name' => $info['name']]); $column->dbType($dbType); - $column->allowNull(!$info['notnull']); + $column->notNull((bool) $info['notnull']); $column->primaryKey((bool) $info['pk']); $column->defaultValue($this->normalizeDefaultValue($info['dflt_value'], $column)); diff --git a/tests/ConnectionTest.php b/tests/ConnectionTest.php index 83371fc2..c6472935 100644 --- a/tests/ConnectionTest.php +++ b/tests/ConnectionTest.php @@ -14,7 +14,6 @@ use Yiisoft\Db\Exception\InvalidConfigException; use Yiisoft\Db\Exception\NotSupportedException; use Yiisoft\Db\Profiler\ProfilerInterface; -use Yiisoft\Db\Sqlite\Column\ColumnFactory; use Yiisoft\Db\Sqlite\Tests\Support\TestTrait; use Yiisoft\Db\Tests\Common\CommonConnectionTest; use Yiisoft\Db\Transaction\TransactionInterface; @@ -182,13 +181,6 @@ private function runExceptionTest(ConnectionInterface $db): void $this->assertTrue($thrown, 'An exception should have been thrown by the command.'); } - public function testGetColumnFactory(): void - { - $db = $this->getConnection(); - - $this->assertInstanceOf(ColumnFactory::class, $db->getColumnFactory()); - } - private function createProfiler(): ProfilerInterface { return $this->createMock(ProfilerInterface::class); diff --git a/tests/Provider/QueryBuilderProvider.php b/tests/Provider/QueryBuilderProvider.php index 5934a913..2e050c11 100644 --- a/tests/Provider/QueryBuilderProvider.php +++ b/tests/Provider/QueryBuilderProvider.php @@ -4,6 +4,7 @@ namespace Yiisoft\Db\Sqlite\Tests\Provider; +use Yiisoft\Db\Constant\PseudoType; use Yiisoft\Db\Expression\Expression; use Yiisoft\Db\Expression\JsonExpression; use Yiisoft\Db\Query\Query; @@ -257,4 +258,36 @@ public static function upsert(): array return $upsert; } + + public static function buildColumnDefinition(): array + { + $values = parent::buildColumnDefinition(); + + $values[PseudoType::PK][0] = 'integer PRIMARY KEY AUTOINCREMENT NOT NULL'; + $values[PseudoType::UPK][0] = 'integer PRIMARY KEY AUTOINCREMENT NOT NULL'; + $values[PseudoType::BIGPK][0] = 'integer PRIMARY KEY AUTOINCREMENT NOT NULL'; + $values[PseudoType::UBIGPK][0] = 'integer PRIMARY KEY AUTOINCREMENT NOT NULL'; + $values[PseudoType::UUID_PK][0] = 'blob(16) PRIMARY KEY NOT NULL'; + $values[PseudoType::UUID_PK_SEQ][0] = 'blob(16) PRIMARY KEY NOT NULL'; + $values['primaryKey()'][0] = 'integer PRIMARY KEY AUTOINCREMENT NOT NULL'; + $values['primaryKey(false)'][0] = 'integer PRIMARY KEY NOT NULL'; + $values['smallPrimaryKey()'][0] = 'integer PRIMARY KEY AUTOINCREMENT NOT NULL'; + $values['smallPrimaryKey(false)'][0] = 'smallint PRIMARY KEY NOT NULL'; + $values['bigPrimaryKey()'][0] = 'integer PRIMARY KEY AUTOINCREMENT NOT NULL'; + $values['bigPrimaryKey(false)'][0] = 'bigint PRIMARY KEY NOT NULL'; + $values['uuidPrimaryKey()'][0] = 'blob(16) PRIMARY KEY NOT NULL'; + $values['uuidPrimaryKey(false)'][0] = 'blob(16) PRIMARY KEY NOT NULL'; + $values['money()'][0] = 'decimal(19,4)'; + $values['money(10)'][0] = 'decimal(10,4)'; + $values['money(10,2)'][0] = 'decimal(10,2)'; + $values['money(null)'][0] = 'decimal'; + $values['binary()'][0] = 'blob'; + $values['binary(1000)'][0] = 'blob(1000)'; + $values['uuid()'][0] = 'blob(16)'; + $values["comment('comment')"][0] = 'varchar(255) /* comment */'; + $values['integer()->primaryKey()'][0] = 'integer PRIMARY KEY NOT NULL'; + $values['unsigned()'][0] = 'integer'; + + return $values; + } } diff --git a/tests/Provider/SchemaProvider.php b/tests/Provider/SchemaProvider.php index ac47dd20..f04bc4c9 100644 --- a/tests/Provider/SchemaProvider.php +++ b/tests/Provider/SchemaProvider.php @@ -19,11 +19,10 @@ public static function columns(): array 'dbType' => 'integer', 'phpType' => 'int', 'primaryKey' => false, - 'allowNull' => false, + 'notNull' => true, 'autoIncrement' => false, 'enumValues' => null, 'size' => null, - 'precision' => null, 'scale' => null, 'defaultValue' => null, ], @@ -32,11 +31,10 @@ public static function columns(): array 'dbType' => 'integer', 'phpType' => 'int', 'primaryKey' => false, - 'allowNull' => true, + 'notNull' => false, 'autoIncrement' => false, 'enumValues' => null, 'size' => null, - 'precision' => null, 'scale' => null, 'defaultValue' => 1, ], @@ -45,11 +43,10 @@ public static function columns(): array 'dbType' => 'tinyint(3)', 'phpType' => 'int', 'primaryKey' => false, - 'allowNull' => true, + 'notNull' => false, 'autoIncrement' => false, 'enumValues' => null, 'size' => 3, - 'precision' => 3, 'scale' => null, 'defaultValue' => 1, ], @@ -58,11 +55,10 @@ public static function columns(): array 'dbType' => 'smallint(1)', 'phpType' => 'int', 'primaryKey' => false, - 'allowNull' => true, + 'notNull' => false, 'autoIncrement' => false, 'enumValues' => null, 'size' => 1, - 'precision' => 1, 'scale' => null, 'defaultValue' => 1, ], @@ -71,11 +67,10 @@ public static function columns(): array 'dbType' => 'char(100)', 'phpType' => 'string', 'primaryKey' => false, - 'allowNull' => false, + 'notNull' => true, 'autoIncrement' => false, 'enumValues' => null, 'size' => 100, - 'precision' => 100, 'scale' => null, 'defaultValue' => null, ], @@ -84,11 +79,10 @@ public static function columns(): array 'dbType' => 'varchar(100)', 'phpType' => 'string', 'primaryKey' => false, - 'allowNull' => true, + 'notNull' => false, 'autoIncrement' => false, 'enumValues' => null, 'size' => 100, - 'precision' => 100, 'scale' => null, 'defaultValue' => 'something"', ], @@ -97,11 +91,10 @@ public static function columns(): array 'dbType' => 'text', 'phpType' => 'string', 'primaryKey' => false, - 'allowNull' => true, + 'notNull' => false, 'autoIncrement' => false, 'enumValues' => null, 'size' => null, - 'precision' => null, 'scale' => null, 'defaultValue' => null, ], @@ -110,11 +103,10 @@ public static function columns(): array 'dbType' => 'double(4,3)', 'phpType' => 'float', 'primaryKey' => false, - 'allowNull' => false, + 'notNull' => true, 'autoIncrement' => false, 'enumValues' => null, 'size' => 4, - 'precision' => 4, 'scale' => 3, 'defaultValue' => null, ], @@ -123,11 +115,10 @@ public static function columns(): array 'dbType' => 'double', 'phpType' => 'float', 'primaryKey' => false, - 'allowNull' => true, + 'notNull' => false, 'autoIncrement' => false, 'enumValues' => null, 'size' => null, - 'precision' => null, 'scale' => null, 'defaultValue' => 1.23, ], @@ -136,11 +127,10 @@ public static function columns(): array 'dbType' => 'blob', 'phpType' => 'mixed', 'primaryKey' => false, - 'allowNull' => true, + 'notNull' => false, 'autoIncrement' => false, 'enumValues' => null, 'size' => null, - 'precision' => null, 'scale' => null, 'defaultValue' => null, ], @@ -149,11 +139,10 @@ public static function columns(): array 'dbType' => 'decimal(5,2)', 'phpType' => 'float', 'primaryKey' => false, - 'allowNull' => true, + 'notNull' => false, 'autoIncrement' => false, 'enumValues' => null, 'size' => 5, - 'precision' => 5, 'scale' => 2, 'defaultValue' => 33.22, ], @@ -162,11 +151,10 @@ public static function columns(): array 'dbType' => 'timestamp', 'phpType' => 'string', 'primaryKey' => false, - 'allowNull' => false, + 'notNull' => true, 'autoIncrement' => false, 'enumValues' => null, 'size' => null, - 'precision' => null, 'scale' => null, 'defaultValue' => '2002-01-01 00:00:00', ], @@ -175,11 +163,10 @@ public static function columns(): array 'dbType' => 'tinyint(1)', 'phpType' => 'bool', 'primaryKey' => false, - 'allowNull' => false, + 'notNull' => true, 'autoIncrement' => false, 'enumValues' => null, 'size' => 1, - 'precision' => 1, 'scale' => null, 'defaultValue' => null, ], @@ -188,11 +175,10 @@ public static function columns(): array 'dbType' => 'tinyint(1)', 'phpType' => 'bool', 'primaryKey' => false, - 'allowNull' => true, + 'notNull' => false, 'autoIncrement' => false, 'enumValues' => null, 'size' => 1, - 'precision' => 1, 'scale' => null, 'defaultValue' => true, ], @@ -201,11 +187,10 @@ public static function columns(): array 'dbType' => 'timestamp', 'phpType' => 'string', 'primaryKey' => false, - 'allowNull' => false, + 'notNull' => true, 'autoIncrement' => false, 'enumValues' => null, 'size' => null, - 'precision' => null, 'scale' => null, 'defaultValue' => new Expression('CURRENT_TIMESTAMP'), ], @@ -214,11 +199,10 @@ public static function columns(): array 'dbType' => 'bit(8)', 'phpType' => 'int', 'primaryKey' => false, - 'allowNull' => false, + 'notNull' => true, 'autoIncrement' => false, 'enumValues' => null, 'size' => 8, - 'precision' => 8, 'scale' => null, 'defaultValue' => 0b1000_0010, // 130 ], @@ -227,11 +211,10 @@ public static function columns(): array 'dbType' => 'json', 'phpType' => 'mixed', 'primaryKey' => false, - 'allowNull' => false, + 'notNull' => true, 'autoIncrement' => false, 'enumValues' => null, 'size' => null, - 'precision' => null, 'scale' => null, 'defaultValue' => ['number' => 10], ], @@ -240,11 +223,10 @@ public static function columns(): array 'dbType' => 'json', 'phpType' => 'mixed', 'primaryKey' => false, - 'allowNull' => true, + 'notNull' => false, 'autoIncrement' => false, 'enumValues' => null, 'size' => null, - 'precision' => null, 'scale' => null, 'defaultValue' => null, ], @@ -258,11 +240,10 @@ public static function columns(): array 'dbType' => 'integer', 'phpType' => 'int', 'primaryKey' => true, - 'allowNull' => false, + 'notNull' => true, 'autoIncrement' => true, 'enumValues' => null, 'size' => null, - 'precision' => null, 'scale' => null, 'defaultValue' => null, ], @@ -271,11 +252,10 @@ public static function columns(): array 'dbType' => 'varchar(255)', 'phpType' => 'string', 'primaryKey' => false, - 'allowNull' => false, + 'notNull' => true, 'autoIncrement' => false, 'enumValues' => null, 'size' => 255, - 'precision' => 255, 'scale' => null, 'defaultValue' => null, ], @@ -289,11 +269,10 @@ public static function columns(): array 'dbType' => 'integer', 'phpType' => 'int', 'primaryKey' => true, - 'allowNull' => true, + 'notNull' => false, 'autoIncrement' => true, 'enumValues' => null, 'size' => null, - 'precision' => null, 'scale' => null, 'defaultValue' => null, ], @@ -302,11 +281,10 @@ public static function columns(): array 'dbType' => 'text', 'phpType' => 'string', 'primaryKey' => false, - 'allowNull' => false, + 'notNull' => true, 'autoIncrement' => false, 'enumValues' => null, 'size' => null, - 'precision' => null, 'scale' => null, 'defaultValue' => 'CURRENT_TIMESTAMP', ], @@ -315,11 +293,10 @@ public static function columns(): array 'dbType' => 'text', 'phpType' => 'string', 'primaryKey' => false, - 'allowNull' => false, + 'notNull' => true, 'autoIncrement' => false, 'enumValues' => null, 'size' => null, - 'precision' => null, 'scale' => null, 'defaultValue' => new Expression('CURRENT_TIMESTAMP'), ], @@ -339,11 +316,10 @@ public static function columnsTypeBit(): array 'dbType' => 'bit(1)', 'phpType' => 'bool', 'primaryKey' => false, - 'allowNull' => false, + 'notNull' => true, 'autoIncrement' => false, 'enumValues' => null, 'size' => 1, - 'precision' => 1, 'scale' => null, 'defaultValue' => null, ], @@ -352,11 +328,10 @@ public static function columnsTypeBit(): array 'dbType' => 'bit(1)', 'phpType' => 'bool', 'primaryKey' => false, - 'allowNull' => true, + 'notNull' => false, 'autoIncrement' => false, 'enumValues' => null, 'size' => 1, - 'precision' => 1, 'scale' => null, 'defaultValue' => true, ], @@ -365,11 +340,10 @@ public static function columnsTypeBit(): array 'dbType' => 'bit(32)', 'phpType' => 'int', 'primaryKey' => false, - 'allowNull' => false, + 'notNull' => true, 'autoIncrement' => false, 'enumValues' => null, 'size' => 32, - 'precision' => 32, 'scale' => null, 'defaultValue' => null, ], @@ -378,11 +352,10 @@ public static function columnsTypeBit(): array 'dbType' => 'bit(32)', 'phpType' => 'int', 'primaryKey' => false, - 'allowNull' => true, + 'notNull' => false, 'autoIncrement' => false, 'enumValues' => null, 'size' => 32, - 'precision' => 32, 'scale' => null, 'defaultValue' => 1, ], @@ -391,11 +364,10 @@ public static function columnsTypeBit(): array 'dbType' => 'bit(64)', 'phpType' => 'int', 'primaryKey' => false, - 'allowNull' => false, + 'notNull' => true, 'autoIncrement' => false, 'enumValues' => null, 'size' => 64, - 'precision' => 64, 'scale' => null, 'defaultValue' => null, ], @@ -404,11 +376,10 @@ public static function columnsTypeBit(): array 'dbType' => 'bit(64)', 'phpType' => 'int', 'primaryKey' => false, - 'allowNull' => true, + 'notNull' => false, 'autoIncrement' => false, 'enumValues' => null, 'size' => 64, - 'precision' => 64, 'scale' => null, 'defaultValue' => 1, ], diff --git a/tests/QueryBuilderTest.php b/tests/QueryBuilderTest.php index 3f65ed1d..f33fbc8b 100644 --- a/tests/QueryBuilderTest.php +++ b/tests/QueryBuilderTest.php @@ -16,6 +16,7 @@ use Yiisoft\Db\Query\Query; use Yiisoft\Db\Query\QueryInterface; use Yiisoft\Db\QueryBuilder\Condition\JsonOverlapsCondition; +use Yiisoft\Db\Schema\Column\ColumnSchemaInterface; use Yiisoft\Db\Sqlite\Column; use Yiisoft\Db\Sqlite\Tests\Support\TestTrait; use Yiisoft\Db\Tests\Common\CommonQueryBuilderTest; @@ -835,4 +836,10 @@ public function testJsonOverlapsConditionOperator(iterable|ExpressionInterface $ $db->close(); } + + /** @dataProvider \Yiisoft\Db\Sqlite\Tests\Provider\QueryBuilderProvider::buildColumnDefinition() */ + public function testBuildColumnDefinition(string $expected, ColumnSchemaInterface|string $column): void + { + parent::testBuildColumnDefinition($expected, $column); + } } diff --git a/tests/SchemaTest.php b/tests/SchemaTest.php index 2a171127..37bc703f 100644 --- a/tests/SchemaTest.php +++ b/tests/SchemaTest.php @@ -11,6 +11,7 @@ use Yiisoft\Db\Exception\Exception; use Yiisoft\Db\Exception\InvalidConfigException; use Yiisoft\Db\Exception\NotSupportedException; +use Yiisoft\Db\Sqlite\Column\ColumnFactory; use Yiisoft\Db\Sqlite\Schema; use Yiisoft\Db\Sqlite\Tests\Support\TestTrait; use Yiisoft\Db\Tests\Common\CommonSchemaTest; @@ -359,4 +360,11 @@ public function testNotConnectionPDO(): void $schema->refresh(); } + + public function testGetColumnFactory(): void + { + $db = $this->getConnection(); + + $this->assertInstanceOf(ColumnFactory::class, $db->getSchema()->getColumnFactory()); + } }