Skip to content

Commit

Permalink
Rename ColumnSchemaInterface to ColumnInterface (#298)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tigrov authored Jan 9, 2025
1 parent 349655b commit 3f867e3
Show file tree
Hide file tree
Showing 15 changed files with 78 additions and 78 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
- Chg #294: Update `QueryBuilder` constructor (@Tigrov)
- Enh #293: Use `ColumnDefinitionBuilder` to generate table column SQL representation (@Tigrov)
- Enh #296: Remove `ColumnInterface` (@Tigrov)
- Enh #298: Rename `ColumnSchemaInterface` to `ColumnInterface` (@Tigrov)
- Enh #298: Refactor `DMLQueryBuilder::prepareInsertValues()` method (@Tigrov)

## 1.3.0 March 21, 2024

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

use Yiisoft\Db\Command\ParamInterface;
use Yiisoft\Db\Expression\Expression;
use Yiisoft\Db\Schema\Column\BinaryColumnSchema as BaseBinaryColumnSchema;
use Yiisoft\Db\Schema\Column\BinaryColumn as BaseBinaryColumn;

use function is_string;

final class BinaryColumnSchema extends BaseBinaryColumnSchema
final class BinaryColumn extends BaseBinaryColumn
{
public function dbTypecast(mixed $value): mixed
{
Expand Down
6 changes: 3 additions & 3 deletions src/Column/ColumnBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
namespace Yiisoft\Db\Oracle\Column;

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

final class ColumnBuilder extends \Yiisoft\Db\Schema\Column\ColumnBuilder
{
public static function binary(int|null $size = null): ColumnSchemaInterface
public static function binary(int|null $size = null): ColumnInterface
{
return new BinaryColumnSchema(ColumnType::BINARY, size: $size);
return new BinaryColumn(ColumnType::BINARY, size: $size);
}
}
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 ceil;
use function log10;
Expand Down Expand Up @@ -35,7 +35,7 @@ final class ColumnDefinitionBuilder extends AbstractColumnDefinitionBuilder
'number',
];

public function build(ColumnSchemaInterface $column): string
public function build(ColumnInterface $column): string
{
return $this->buildType($column)
. $this->buildAutoIncrement($column)
Expand All @@ -62,7 +62,7 @@ protected function buildOnUpdate(string $onUpdate): string
return '';
}

protected function getDbType(ColumnSchemaInterface $column): string
protected function getDbType(ColumnInterface $column): string
{
$size = $column->getSize();

Expand Down
6 changes: 3 additions & 3 deletions src/Column/ColumnFactory.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\Schema\Column\AbstractColumnFactory;
use Yiisoft\Db\Schema\Column\ColumnSchemaInterface;
use Yiisoft\Db\Schema\Column\ColumnInterface;

use function preg_replace;
use function rtrim;
Expand Down Expand Up @@ -73,13 +73,13 @@ protected function getType(string $dbType, array $info = []): string
protected function getColumnClass(string $type, array $info = []): string
{
if ($type === ColumnType::BINARY) {
return BinaryColumnSchema::class;
return BinaryColumn::class;
}

return parent::getColumnClass($type, $info);
}

protected function normalizeNotNullDefaultValue(string $defaultValue, ColumnSchemaInterface $column): mixed
protected function normalizeNotNullDefaultValue(string $defaultValue, ColumnInterface $column): mixed
{
return parent::normalizeNotNullDefaultValue(rtrim($defaultValue), $column);
}
Expand Down
6 changes: 3 additions & 3 deletions src/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function insertWithReturningPks(string $table, array $columns): bool|arra
$params = [];
$sql = $this->getQueryBuilder()->insert($table, $columns, $params);

$columnSchemas = $tableSchema?->getColumns() ?? [];
$tableColumns = $tableSchema?->getColumns() ?? [];
$returnParams = [];
$returning = [];

Expand All @@ -49,13 +49,13 @@ public function insertWithReturningPks(string $table, array $columns): bool|arra
'value' => '',
];

if (!isset($columnSchemas[$name]) || $columnSchemas[$name]->getPhpType() !== PhpType::INT) {
if (!isset($tableColumns[$name]) || $tableColumns[$name]->getPhpType() !== PhpType::INT) {
$returnParams[$phName]['dataType'] = PDO::PARAM_STR;
} else {
$returnParams[$phName]['dataType'] = PDO::PARAM_INT;
}

$returnParams[$phName]['size'] = ($columnSchemas[$name]?->getSize() ?? 3998) + 2;
$returnParams[$phName]['size'] = ($tableColumns[$name]?->getSize() ?? 3998) + 2;

$returning[] = $this->db->getQuoter()->quoteColumnName($name);
}
Expand Down
4 changes: 2 additions & 2 deletions src/DDLQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Yiisoft\Db\Exception\Exception;
use Yiisoft\Db\Exception\NotSupportedException;
use Yiisoft\Db\QueryBuilder\AbstractDDLQueryBuilder;
use Yiisoft\Db\Schema\Column\ColumnSchemaInterface;
use Yiisoft\Db\Schema\Column\ColumnInterface;

/**
* Implements a (Data Definition Language) SQL statements for Oracle Server.
Expand Down Expand Up @@ -45,7 +45,7 @@ public function addForeignKey(
return $sql;
}

public function alterColumn(string $table, string $column, ColumnSchemaInterface|string $type): string
public function alterColumn(string $table, string $column, ColumnInterface|string $type): string
{
return 'ALTER TABLE '
. $this->quoter->quoteTableName($table)
Expand Down
12 changes: 5 additions & 7 deletions src/DMLQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Yiisoft\Db\Query\QueryInterface;
use Yiisoft\Db\QueryBuilder\AbstractDMLQueryBuilder;

use function array_fill;
use function array_key_first;
use function array_map;
use function implode;
Expand Down Expand Up @@ -142,16 +143,13 @@ protected function prepareInsertValues(string $table, array|QueryInterface $colu

if ($tableSchema !== null) {
if (!empty($tableSchema->getPrimaryKey())) {
$columns = $tableSchema->getPrimaryKey();
$names = array_map($this->quoter->quoteColumnName(...), $tableSchema->getPrimaryKey());
} else {
/** @var list<string> $columns */
$columns = [array_key_first($tableSchema->getColumns())];
/** @psalm-suppress PossiblyNullArgument */
$names = [$this->quoter->quoteColumnName(array_key_first($tableSchema->getColumns()))];
}

foreach ($columns as $name) {
$names[] = $this->quoter->quoteColumnName($name);
$placeholders[] = 'DEFAULT';
}
$placeholders = array_fill(0, count($names), 'DEFAULT');
}

return [$names, $placeholders, '', $params];
Expand Down
10 changes: 5 additions & 5 deletions src/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use Yiisoft\Db\Helper\DbArrayHelper;
use Yiisoft\Db\Oracle\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 @@ -389,7 +389,7 @@ protected function findColumns(TableSchemaInterface $table): bool
$info['table'] = $tableName;

/** @psalm-var ColumnArray $info */
$column = $this->loadColumnSchema($info);
$column = $this->loadColumn($info);

$table->column($info['column_name'], $column);
}
Expand Down Expand Up @@ -427,15 +427,15 @@ protected function getTableSequenceName(string $tableName): string|null
}

/**
* 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
{
return $this->getColumnFactory()->fromDbType($info['data_type'], [
'autoIncrement' => $info['identity_column'] === 'YES',
Expand Down
30 changes: 15 additions & 15 deletions tests/ColumnSchemaTest.php → tests/ColumnTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@
use PDO;
use Yiisoft\Db\Command\Param;
use Yiisoft\Db\Expression\Expression;
use Yiisoft\Db\Oracle\Column\BinaryColumnSchema;
use Yiisoft\Db\Oracle\Column\BinaryColumn;
use Yiisoft\Db\Oracle\Tests\Support\TestTrait;
use Yiisoft\Db\Query\Query;
use Yiisoft\Db\Schema\Column\DoubleColumnSchema;
use Yiisoft\Db\Schema\Column\IntegerColumnSchema;
use Yiisoft\Db\Schema\Column\StringColumnSchema;
use Yiisoft\Db\Tests\Common\CommonColumnSchemaTest;
use Yiisoft\Db\Schema\Column\DoubleColumn;
use Yiisoft\Db\Schema\Column\IntegerColumn;
use Yiisoft\Db\Schema\Column\StringColumn;
use Yiisoft\Db\Tests\Common\CommonColumnTest;

use function str_repeat;

/**
* @group oracle
*/
final class ColumnSchemaTest extends CommonColumnSchemaTest
final class ColumnTest extends CommonColumnTest
{
use TestTrait;

Expand Down Expand Up @@ -69,33 +69,33 @@ 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(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'));
}

/** @dataProvider \Yiisoft\Db\Oracle\Tests\Provider\ColumnSchemaProvider::predefinedTypes */
/** @dataProvider \Yiisoft\Db\Oracle\Tests\Provider\ColumnProvider::predefinedTypes */
public function testPredefinedType(string $className, string $type, string $phpType): void
{
parent::testPredefinedType($className, $type, $phpType);
}

/** @dataProvider \Yiisoft\Db\Oracle\Tests\Provider\ColumnSchemaProvider::dbTypecastColumns */
/** @dataProvider \Yiisoft\Db\Oracle\Tests\Provider\ColumnProvider::dbTypecastColumns */
public function testDbTypecastColumns(string $className, array $values): void
{
parent::testDbTypecastColumns($className, $values);
}

public function testBinaryColumnSchema(): void
public function testBinaryColumn(): void
{
$binaryCol = new BinaryColumnSchema();
$binaryCol = new BinaryColumn();
$binaryCol->dbType('BLOB');

$this->assertInstanceOf(Expression::class, $binaryCol->dbTypecast("\x10\x11\x12"));
Expand Down
6 changes: 3 additions & 3 deletions tests/Provider/ColumnBuilderProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@

namespace Yiisoft\Db\Oracle\Tests\Provider;

use Yiisoft\Db\Oracle\Column\BinaryColumnSchema;
use Yiisoft\Db\Oracle\Column\BinaryColumn;

class ColumnBuilderProvider extends \Yiisoft\Db\Tests\Provider\ColumnBuilderProvider
{
public static function buildingMethods(): array
{
$values = parent::buildingMethods();

$values['binary()'][2] = BinaryColumnSchema::class;
$values['binary(8)'][2] = BinaryColumnSchema::class;
$values['binary()'][2] = BinaryColumn::class;
$values['binary(8)'][2] = BinaryColumn::class;

return $values;
}
Expand Down
46 changes: 23 additions & 23 deletions tests/Provider/ColumnFactoryProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,36 @@

use Yiisoft\Db\Constant\ColumnType;
use Yiisoft\Db\Expression\Expression;
use Yiisoft\Db\Oracle\Column\BinaryColumnSchema;
use Yiisoft\Db\Schema\Column\DoubleColumnSchema;
use Yiisoft\Db\Schema\Column\StringColumnSchema;
use Yiisoft\Db\Oracle\Column\BinaryColumn;
use Yiisoft\Db\Schema\Column\DoubleColumn;
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
['char', ColumnType::CHAR, StringColumnSchema::class],
['nchar', ColumnType::CHAR, StringColumnSchema::class],
['varchar2', ColumnType::STRING, StringColumnSchema::class],
['nvarchar2', ColumnType::STRING, StringColumnSchema::class],
['clob', ColumnType::TEXT, StringColumnSchema::class],
['nclob', ColumnType::TEXT, StringColumnSchema::class],
['long', ColumnType::TEXT, StringColumnSchema::class],
['blob', ColumnType::BINARY, BinaryColumnSchema::class],
['bfile', ColumnType::BINARY, BinaryColumnSchema::class],
['long raw', ColumnType::BINARY, BinaryColumnSchema::class],
['raw', ColumnType::BINARY, BinaryColumnSchema::class],
['number', ColumnType::DOUBLE, DoubleColumnSchema::class],
['binary_float', ColumnType::FLOAT, DoubleColumnSchema::class],
['binary_double', ColumnType::DOUBLE, DoubleColumnSchema::class],
['float', ColumnType::DOUBLE, DoubleColumnSchema::class],
['date', ColumnType::DATE, StringColumnSchema::class],
['interval day(0) to second', ColumnType::TIME, StringColumnSchema::class],
['timestamp', ColumnType::TIMESTAMP, StringColumnSchema::class],
['timestamp with time zone', ColumnType::TIMESTAMP, StringColumnSchema::class],
['timestamp with local time zone', ColumnType::TIMESTAMP, StringColumnSchema::class],
['char', ColumnType::CHAR, StringColumn::class],
['nchar', ColumnType::CHAR, StringColumn::class],
['varchar2', ColumnType::STRING, StringColumn::class],
['nvarchar2', ColumnType::STRING, StringColumn::class],
['clob', ColumnType::TEXT, StringColumn::class],
['nclob', ColumnType::TEXT, StringColumn::class],
['long', ColumnType::TEXT, StringColumn::class],
['blob', ColumnType::BINARY, BinaryColumn::class],
['bfile', ColumnType::BINARY, BinaryColumn::class],
['long raw', ColumnType::BINARY, BinaryColumn::class],
['raw', ColumnType::BINARY, BinaryColumn::class],
['number', ColumnType::DOUBLE, DoubleColumn::class],
['binary_float', ColumnType::FLOAT, DoubleColumn::class],
['binary_double', ColumnType::DOUBLE, DoubleColumn::class],
['float', ColumnType::DOUBLE, DoubleColumn::class],
['date', ColumnType::DATE, StringColumn::class],
['interval day(0) to second', ColumnType::TIME, StringColumn::class],
['timestamp', ColumnType::TIMESTAMP, StringColumn::class],
['timestamp with time zone', ColumnType::TIMESTAMP, StringColumn::class],
['timestamp with local time zone', ColumnType::TIMESTAMP, StringColumn::class],
];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@

namespace Yiisoft\Db\Oracle\Tests\Provider;

use Yiisoft\Db\Oracle\Column\BinaryColumnSchema;
use Yiisoft\Db\Oracle\Column\BinaryColumn;

class ColumnSchemaProvider extends \Yiisoft\Db\Tests\Provider\ColumnSchemaProvider
class ColumnProvider extends \Yiisoft\Db\Tests\Provider\ColumnProvider
{
public static function predefinedTypes(): array
{
$values = parent::predefinedTypes();
$values['binary'][0] = BinaryColumnSchema::class;
$values['binary'][0] = BinaryColumn::class;

return $values;
}

public static function dbTypecastColumns(): array
{
$values = parent::dbTypecastColumns();
$values['binary'][0] = BinaryColumnSchema::class;
$values['binary'][0] = BinaryColumn::class;

return $values;
}
Expand Down
Loading

0 comments on commit 3f867e3

Please sign in to comment.