Skip to content

Commit

Permalink
Rename ColumnSchemaInterface to ColumnInterface (#372)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tigrov authored Jan 9, 2025
1 parent 5e75c14 commit 76ef139
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 91 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
- Chg #368: Update `QueryBuilder` constructor (@Tigrov)
- Enh #367: Use `ColumnDefinitionBuilder` to generate table column SQL representation (@Tigrov)
- Enh #371: Remove `ColumnInterface` (@Tigrov)
- Enh #372: Rename `ColumnSchemaInterface` to `ColumnInterface` (@Tigrov)

## 1.2.0 March 21, 2024

Expand Down
6 changes: 3 additions & 3 deletions src/Column/ColumnDefinitionBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Yiisoft\Db\Constant\ColumnType;
use Yiisoft\Db\QueryBuilder\AbstractColumnDefinitionBuilder;
use Yiisoft\Db\Schema\Column\ColumnSchemaInterface;
use Yiisoft\Db\Schema\Column\ColumnInterface;

use function str_contains;
use function version_compare;
Expand Down Expand Up @@ -61,14 +61,14 @@ final class ColumnDefinitionBuilder extends AbstractColumnDefinitionBuilder
'fixed',
];

protected function buildComment(ColumnSchemaInterface $column): string
protected function buildComment(ColumnInterface $column): string
{
$comment = $column->getComment();

return $comment === null ? '' : ' COMMENT ' . $this->queryBuilder->quoter()->quoteValue($comment);
}

protected function getDbType(ColumnSchemaInterface $column): string
protected function getDbType(ColumnInterface $column): string
{
/** @psalm-suppress DocblockTypeContradiction */
$dbType = $column->getDbType() ?? match ($column->getType()) {
Expand Down
6 changes: 3 additions & 3 deletions src/Column/ColumnFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Yiisoft\Db\Constant\ColumnType;
use Yiisoft\Db\Expression\Expression;
use Yiisoft\Db\Schema\Column\AbstractColumnFactory;
use Yiisoft\Db\Schema\Column\ColumnSchemaInterface;
use Yiisoft\Db\Schema\Column\ColumnInterface;

use function bindec;
use function in_array;
Expand Down Expand Up @@ -64,7 +64,7 @@ protected function getType(string $dbType, array $info = []): string
return parent::getType($dbType, $info);
}

protected function normalizeDefaultValue(string|null $defaultValue, ColumnSchemaInterface $column): mixed
protected function normalizeDefaultValue(string|null $defaultValue, ColumnInterface $column): mixed
{
if (
$defaultValue === null
Expand All @@ -77,7 +77,7 @@ protected function normalizeDefaultValue(string|null $defaultValue, ColumnSchema
return $this->normalizeNotNullDefaultValue($defaultValue, $column);
}

protected function normalizeNotNullDefaultValue(string $defaultValue, ColumnSchemaInterface $column): mixed
protected function normalizeNotNullDefaultValue(string $defaultValue, ColumnInterface $column): mixed
{
if ($defaultValue === '') {
return $column->phpTypecast($defaultValue);
Expand Down
19 changes: 0 additions & 19 deletions src/DMLQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@

use Yiisoft\Db\Exception\Exception;
use Yiisoft\Db\Exception\InvalidArgumentException;
use Yiisoft\Db\Exception\InvalidConfigException;
use Yiisoft\Db\Exception\NotSupportedException;
use Yiisoft\Db\Expression\Expression;
use Yiisoft\Db\Query\Query;
use Yiisoft\Db\Query\QueryInterface;
use Yiisoft\Db\QueryBuilder\AbstractDMLQueryBuilder;

Expand Down Expand Up @@ -88,23 +86,6 @@ public function upsert(
return $insertSql . ' ON DUPLICATE KEY UPDATE ' . implode(', ', $updates);
}

/**
* Prepares a `VALUES` part for an `INSERT` SQL statement.
*
* @param string $table The table to insert new rows into.
* @param array|QueryInterface $columns The column data (name => value) to insert into the table or instance of
* {@see Query} to perform `INSERT INTO ... SELECT` SQL statement.
* @param array $params The binding parameters that will be generated by this method.
* They should be bound to the DB command later.
*
* @throws Exception
* @throws InvalidArgumentException
* @throws InvalidConfigException
* @throws NotSupportedException
*
* @return array Array of quoted column names, placeholders, values, and params.
* @psalm-return array{0: string[], 1: string[], 2: string, 3: array}
*/
protected function prepareInsertValues(string $table, QueryInterface|array $columns, array $params = []): array
{
if (empty($columns)) {
Expand Down
10 changes: 5 additions & 5 deletions src/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use Yiisoft\Db\Helper\DbArrayHelper;
use Yiisoft\Db\Mysql\Column\ColumnFactory;
use Yiisoft\Db\Schema\Column\ColumnFactoryInterface;
use Yiisoft\Db\Schema\Column\ColumnSchemaInterface;
use Yiisoft\Db\Schema\Column\ColumnInterface;
use Yiisoft\Db\Schema\TableSchemaInterface;

use function array_change_key_case;
Expand Down Expand Up @@ -173,7 +173,7 @@ protected function findColumns(TableSchemaInterface $table): bool
}

/** @psalm-var ColumnArray $info */
$column = $this->loadColumnSchema($info);
$column = $this->loadColumn($info);
$table->column($info['column_name'], $column);

if ($column->isPrimaryKey()) {
Expand Down Expand Up @@ -390,15 +390,15 @@ protected function getCreateTableSql(TableSchemaInterface $table): string
}

/**
* Loads the column information into a {@see ColumnSchemaInterface} object.
* Loads the column information into a {@see ColumnInterface} object.
*
* @param array $info The column information.
*
* @return ColumnSchemaInterface The column schema object.
* @return ColumnInterface The column object.
*
* @psalm-param ColumnArray $info The column information.
*/
private function loadColumnSchema(array $info): ColumnSchemaInterface
private function loadColumn(array $info): ColumnInterface
{
$extra = trim(str_ireplace('auto_increment', '', $info['extra'], $autoIncrement));

Expand Down
32 changes: 16 additions & 16 deletions tests/ColumnSchemaTest.php → tests/ColumnTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
use Yiisoft\Db\Mysql\Column\ColumnBuilder;
use Yiisoft\Db\Mysql\Tests\Support\TestTrait;
use Yiisoft\Db\Query\Query;
use Yiisoft\Db\Schema\Column\BinaryColumnSchema;
use Yiisoft\Db\Schema\Column\BooleanColumnSchema;
use Yiisoft\Db\Schema\Column\DoubleColumnSchema;
use Yiisoft\Db\Schema\Column\IntegerColumnSchema;
use Yiisoft\Db\Schema\Column\JsonColumnSchema;
use Yiisoft\Db\Schema\Column\StringColumnSchema;
use Yiisoft\Db\Tests\Common\CommonColumnSchemaTest;
use Yiisoft\Db\Schema\Column\BinaryColumn;
use Yiisoft\Db\Schema\Column\BooleanColumn;
use Yiisoft\Db\Schema\Column\DoubleColumn;
use Yiisoft\Db\Schema\Column\IntegerColumn;
use Yiisoft\Db\Schema\Column\JsonColumn;
use Yiisoft\Db\Schema\Column\StringColumn;
use Yiisoft\Db\Tests\Common\CommonColumnTest;

use function str_repeat;

Expand All @@ -24,12 +24,12 @@
*
* @psalm-suppress PropertyNotSetInConstructor
*/
final class ColumnSchemaTest extends CommonColumnSchemaTest
final class ColumnTest extends CommonColumnTest
{
use TestTrait;

/**
* @dataProvider \Yiisoft\Db\Mysql\Tests\Provider\ColumnSchemaProvider::bigIntValue
* @dataProvider \Yiisoft\Db\Mysql\Tests\Provider\ColumnProvider::bigIntValue
*
* @throws Exception
* @throws Throwable
Expand Down Expand Up @@ -99,18 +99,18 @@ public function testPhpTypeCast(): void
$db->close();
}

public function testColumnSchemaInstance(): void
public function testColumnInstance(): void
{
$db = $this->getConnection(true);
$schema = $db->getSchema();
$tableSchema = $schema->getTableSchema('type');

$this->assertInstanceOf(IntegerColumnSchema::class, $tableSchema->getColumn('int_col'));
$this->assertInstanceOf(StringColumnSchema::class, $tableSchema->getColumn('char_col'));
$this->assertInstanceOf(DoubleColumnSchema::class, $tableSchema->getColumn('float_col'));
$this->assertInstanceOf(BinaryColumnSchema::class, $tableSchema->getColumn('blob_col'));
$this->assertInstanceOf(BooleanColumnSchema::class, $tableSchema->getColumn('bool_col'));
$this->assertInstanceOf(JsonColumnSchema::class, $tableSchema->getColumn('json_col'));
$this->assertInstanceOf(IntegerColumn::class, $tableSchema->getColumn('int_col'));
$this->assertInstanceOf(StringColumn::class, $tableSchema->getColumn('char_col'));
$this->assertInstanceOf(DoubleColumn::class, $tableSchema->getColumn('float_col'));
$this->assertInstanceOf(BinaryColumn::class, $tableSchema->getColumn('blob_col'));
$this->assertInstanceOf(BooleanColumn::class, $tableSchema->getColumn('bool_col'));
$this->assertInstanceOf(JsonColumn::class, $tableSchema->getColumn('json_col'));
}

public function testLongtextType(): void
Expand Down
74 changes: 37 additions & 37 deletions tests/Provider/ColumnFactoryProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,57 +6,57 @@

use Yiisoft\Db\Constant\ColumnType;
use Yiisoft\Db\Expression\Expression;
use Yiisoft\Db\Schema\Column\BinaryColumnSchema;
use Yiisoft\Db\Schema\Column\BitColumnSchema;
use Yiisoft\Db\Schema\Column\BooleanColumnSchema;
use Yiisoft\Db\Schema\Column\DoubleColumnSchema;
use Yiisoft\Db\Schema\Column\IntegerColumnSchema;
use Yiisoft\Db\Schema\Column\JsonColumnSchema;
use Yiisoft\Db\Schema\Column\StringColumnSchema;
use Yiisoft\Db\Schema\Column\BinaryColumn;
use Yiisoft\Db\Schema\Column\BitColumn;
use Yiisoft\Db\Schema\Column\BooleanColumn;
use Yiisoft\Db\Schema\Column\DoubleColumn;
use Yiisoft\Db\Schema\Column\IntegerColumn;
use Yiisoft\Db\Schema\Column\JsonColumn;
use Yiisoft\Db\Schema\Column\StringColumn;

final class ColumnFactoryProvider extends \Yiisoft\Db\Tests\Provider\ColumnFactoryProvider
{
public static function dbTypes(): array
{
return [
// db type, expected abstract type, expected instance of
['bit', ColumnType::BIT, BitColumnSchema::class],
['tinyint', ColumnType::TINYINT, IntegerColumnSchema::class],
['smallint', ColumnType::SMALLINT, IntegerColumnSchema::class],
['mediumint', ColumnType::INTEGER, IntegerColumnSchema::class],
['int', ColumnType::INTEGER, IntegerColumnSchema::class],
['integer', ColumnType::INTEGER, IntegerColumnSchema::class],
['bigint', ColumnType::BIGINT, IntegerColumnSchema::class],
['float', ColumnType::FLOAT, DoubleColumnSchema::class],
['real', ColumnType::FLOAT, DoubleColumnSchema::class],
['double', ColumnType::DOUBLE, DoubleColumnSchema::class],
['decimal', ColumnType::DECIMAL, DoubleColumnSchema::class],
['numeric', ColumnType::DECIMAL, DoubleColumnSchema::class],
['char', ColumnType::CHAR, StringColumnSchema::class],
['varchar', ColumnType::STRING, StringColumnSchema::class],
['string', ColumnType::STRING, StringColumnSchema::class],
['enum', ColumnType::STRING, StringColumnSchema::class],
['tinytext', ColumnType::TEXT, StringColumnSchema::class],
['mediumtext', ColumnType::TEXT, StringColumnSchema::class],
['longtext', ColumnType::TEXT, StringColumnSchema::class],
['text', ColumnType::TEXT, StringColumnSchema::class],
['varbinary', ColumnType::BINARY, BinaryColumnSchema::class],
['blob', ColumnType::BINARY, BinaryColumnSchema::class],
['longblob', ColumnType::BINARY, BinaryColumnSchema::class],
['year', ColumnType::DATE, StringColumnSchema::class],
['date', ColumnType::DATE, StringColumnSchema::class],
['time', ColumnType::TIME, StringColumnSchema::class],
['datetime', ColumnType::DATETIME, StringColumnSchema::class],
['timestamp', ColumnType::TIMESTAMP, StringColumnSchema::class],
['json', ColumnType::JSON, JsonColumnSchema::class],
['bit', ColumnType::BIT, BitColumn::class],
['tinyint', ColumnType::TINYINT, IntegerColumn::class],
['smallint', ColumnType::SMALLINT, IntegerColumn::class],
['mediumint', ColumnType::INTEGER, IntegerColumn::class],
['int', ColumnType::INTEGER, IntegerColumn::class],
['integer', ColumnType::INTEGER, IntegerColumn::class],
['bigint', ColumnType::BIGINT, IntegerColumn::class],
['float', ColumnType::FLOAT, DoubleColumn::class],
['real', ColumnType::FLOAT, DoubleColumn::class],
['double', ColumnType::DOUBLE, DoubleColumn::class],
['decimal', ColumnType::DECIMAL, DoubleColumn::class],
['numeric', ColumnType::DECIMAL, DoubleColumn::class],
['char', ColumnType::CHAR, StringColumn::class],
['varchar', ColumnType::STRING, StringColumn::class],
['string', ColumnType::STRING, StringColumn::class],
['enum', ColumnType::STRING, StringColumn::class],
['tinytext', ColumnType::TEXT, StringColumn::class],
['mediumtext', ColumnType::TEXT, StringColumn::class],
['longtext', ColumnType::TEXT, StringColumn::class],
['text', ColumnType::TEXT, StringColumn::class],
['varbinary', ColumnType::BINARY, BinaryColumn::class],
['blob', ColumnType::BINARY, BinaryColumn::class],
['longblob', ColumnType::BINARY, BinaryColumn::class],
['year', ColumnType::DATE, StringColumn::class],
['date', ColumnType::DATE, StringColumn::class],
['time', ColumnType::TIME, StringColumn::class],
['datetime', ColumnType::DATETIME, StringColumn::class],
['timestamp', ColumnType::TIMESTAMP, StringColumn::class],
['json', ColumnType::JSON, JsonColumn::class],
];
}

public static function definitions(): array
{
$definitions = parent::definitions();

$definitions[] = ['bit(1)', ColumnType::BOOLEAN, BooleanColumnSchema::class, ['getDbType' => 'bit', 'getSize' => 1]];
$definitions[] = ['bit(1)', ColumnType::BOOLEAN, BooleanColumn::class, ['getDbType' => 'bit', 'getSize' => 1]];

return $definitions;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Yiisoft\Db\Mysql\Tests\Provider;

final class ColumnSchemaProvider
final class ColumnProvider
{
public static function bigIntValue(): array
{
Expand Down
6 changes: 3 additions & 3 deletions tests/QueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,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\Schema\Column\ColumnInterface;
use Yiisoft\Db\Tests\Common\CommonQueryBuilderTest;

use function str_contains;
Expand Down Expand Up @@ -146,7 +146,7 @@ public function testAddUnique(string $name, string $table, array|string $columns
}

#[DataProviderExternal(QueryBuilderProvider::class, 'alterColumn')]
public function testAlterColumn(string|ColumnSchemaInterface $type, string $expected): void
public function testAlterColumn(string|ColumnInterface $type, string $expected): void
{
parent::testAlterColumn($type, $expected);
}
Expand Down Expand Up @@ -752,7 +752,7 @@ public function testJsonOverlapsConditionOperator(iterable|ExpressionInterface $
}

/** @dataProvider \Yiisoft\Db\Mysql\Tests\Provider\QueryBuilderProvider::buildColumnDefinition() */
public function testBuildColumnDefinition(string $expected, ColumnSchemaInterface|string $column): void
public function testBuildColumnDefinition(string $expected, ColumnInterface|string $column): void
{
parent::testBuildColumnDefinition($expected, $column);
}
Expand Down
8 changes: 4 additions & 4 deletions tests/SchemaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ final class SchemaTest extends CommonSchemaTest
*
* @throws Exception
*/
public function testColumnSchema(array $columns, string $tableName): void
public function testColumns(array $columns, string $tableName): void
{
$db = $this->getConnection();
$serverVersion = $db->getServerInfo()->getVersion();
Expand Down Expand Up @@ -74,15 +74,15 @@ public function testColumnSchema(array $columns, string $tableName): void
}
}

parent::testColumnSchema($columns, $tableName);
parent::testColumns($columns, $tableName);
}

/**
* @dataProvider \Yiisoft\Db\Mysql\Tests\Provider\SchemaProvider::columnsTypeBit
*/
public function testColumnSchemaWithTypeBit(array $columns): void
public function testColumnWithTypeBit(array $columns): void
{
$this->columnSchema($columns, 'type_bit');
$this->assertTableColumns($columns, 'type_bit');
}

/**
Expand Down

0 comments on commit 76ef139

Please sign in to comment.