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

Rename ColumnSchemaInterface to ColumnInterface #380

Merged
merged 2 commits into from
Jan 9, 2025
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 @@ -25,6 +25,7 @@
- Enh #374: Use `ColumnDefinitionBuilder` to generate table column SQL representation (@Tigrov)
- Enh #378: Improve loading schemas of views (@Tigrov)
- Enh #379: Remove `ColumnInterface` (@Tigrov)
- Enh #380: Rename `ColumnSchemaInterface` to `ColumnInterface` (@Tigrov)

## 1.3.0 March 21, 2024

Expand Down
4 changes: 2 additions & 2 deletions src/Builder/StructuredExpressionBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use Yiisoft\Db\Expression\StructuredExpression;
use Yiisoft\Db\QueryBuilder\QueryBuilderInterface;

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

use function implode;

Expand Down Expand Up @@ -62,7 +62,7 @@ public function build(ExpressionInterface $expression, array &$params = []): str
* Builds a placeholder array out of $expression values.
*
* @param array|object $value The expression value.
* @param ColumnSchemaInterface[] $columns The structured type columns.
* @param ColumnInterface[] $columns The structured type columns.
* @param array $params The binding parameters.
*
* @throws Exception
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
namespace Yiisoft\Db\Pgsql\Column;

use Yiisoft\Db\Pgsql\ArrayParser;
use Yiisoft\Db\Schema\Column\ArrayColumnSchema as BaseArrayColumnSchema;
use Yiisoft\Db\Schema\Column\ArrayColumn as BaseArrayColumn;
use Yiisoft\Db\Syntax\ParserToArrayInterface;

final class ArrayColumnSchema extends BaseArrayColumnSchema
final class ArrayColumn extends BaseArrayColumn
{
protected function getParser(): ParserToArrayInterface
{
Expand Down
12 changes: 12 additions & 0 deletions src/Column/BigIntColumn.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace Yiisoft\Db\Pgsql\Column;

use Yiisoft\Db\Schema\Column\BigIntColumn as BaseBigIntColumn;

final class BigIntColumn extends BaseBigIntColumn implements SequenceColumnInterface
{
use SequenceColumnTrait;
}
12 changes: 0 additions & 12 deletions src/Column/BigIntColumnSchema.php

This file was deleted.

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

namespace Yiisoft\Db\Pgsql\Column;

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

use function hex2bin;
use function is_string;
use function str_starts_with;
use function substr;

final class BinaryColumnSchema extends BaseBinaryColumnSchema
final class BinaryColumn extends BaseBinaryColumn
{
public function phpTypecast(mixed $value): mixed
{
Expand Down
4 changes: 2 additions & 2 deletions src/Column/BitColumnSchema.php → src/Column/BitColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
namespace Yiisoft\Db\Pgsql\Column;

use Yiisoft\Db\Expression\ExpressionInterface;
use Yiisoft\Db\Schema\Column\BitColumnSchema as BaseBitColumnSchema;
use Yiisoft\Db\Schema\Column\BitColumn as BaseBitColumn;

use function bindec;
use function decbin;
use function gettype;
use function str_pad;

final class BitColumnSchema extends BaseBitColumnSchema
final class BitColumn extends BaseBitColumn
{
/** @psalm-suppress RedundantCast */
public function dbTypecast(mixed $value): string|ExpressionInterface|null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

namespace Yiisoft\Db\Pgsql\Column;

use Yiisoft\Db\Schema\Column\BooleanColumnSchema as BaseBooleanColumnSchema;
use Yiisoft\Db\Schema\Column\BooleanColumn as BaseBooleanColumn;

final class BooleanColumnSchema extends BaseBooleanColumnSchema
final class BooleanColumn extends BaseBooleanColumn
{
public function phpTypecast(mixed $value): bool|null
{
Expand Down
38 changes: 19 additions & 19 deletions src/Column/ColumnBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,52 +5,52 @@
namespace Yiisoft\Db\Pgsql\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 boolean(): ColumnSchemaInterface
public static function boolean(): ColumnInterface
{
return new BooleanColumnSchema(ColumnType::BOOLEAN);
return new BooleanColumn(ColumnType::BOOLEAN);
}

public static function bit(int|null $size = null): ColumnSchemaInterface
public static function bit(int|null $size = null): ColumnInterface
{
return new BitColumnSchema(ColumnType::BIT, size: $size);
return new BitColumn(ColumnType::BIT, size: $size);
}

public static function tinyint(int|null $size = null): ColumnSchemaInterface
public static function tinyint(int|null $size = null): ColumnInterface
{
return new IntegerColumnSchema(ColumnType::TINYINT, size: $size);
return new IntegerColumn(ColumnType::TINYINT, size: $size);
}

public static function smallint(int|null $size = null): ColumnSchemaInterface
public static function smallint(int|null $size = null): ColumnInterface
{
return new IntegerColumnSchema(ColumnType::SMALLINT, size: $size);
return new IntegerColumn(ColumnType::SMALLINT, size: $size);
}

public static function integer(int|null $size = null): ColumnSchemaInterface
public static function integer(int|null $size = null): ColumnInterface
{
return new IntegerColumnSchema(ColumnType::INTEGER, size: $size);
return new IntegerColumn(ColumnType::INTEGER, size: $size);
}

public static function bigint(int|null $size = null): ColumnSchemaInterface
public static function bigint(int|null $size = null): ColumnInterface
{
return new IntegerColumnSchema(ColumnType::BIGINT, size: $size);
return new IntegerColumn(ColumnType::BIGINT, size: $size);
}

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);
}

public static function array(ColumnSchemaInterface|null $column = null): ColumnSchemaInterface
public static function array(ColumnInterface|null $column = null): ColumnInterface
{
return new ArrayColumnSchema(ColumnType::ARRAY, column: $column);
return new ArrayColumn(ColumnType::ARRAY, column: $column);
}

public static function structured(string|null $dbType = null, array $columns = []): ColumnSchemaInterface
public static function structured(string|null $dbType = null, array $columns = []): ColumnInterface
{
return new StructuredColumnSchema(ColumnType::STRUCTURED, dbType: $dbType, columns: $columns);
return new StructuredColumn(ColumnType::STRUCTURED, dbType: $dbType, columns: $columns);
}
}
12 changes: 6 additions & 6 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 version_compare;

Expand Down Expand Up @@ -35,7 +35,7 @@ final class ColumnDefinitionBuilder extends AbstractColumnDefinitionBuilder
'numeric',
];

public function build(ColumnSchemaInterface $column): string
public function build(ColumnInterface $column): string
{
return $this->buildType($column)
. $this->buildNotNull($column)
Expand All @@ -47,22 +47,22 @@ public function build(ColumnSchemaInterface $column): string
. $this->buildExtra($column);
}

public function buildAlter(ColumnSchemaInterface $column): string
public function buildAlter(ColumnInterface $column): string
{
return $this->buildType($column)
. $this->buildExtra($column);
}

protected function buildType(ColumnSchemaInterface $column): string
protected function buildType(ColumnInterface $column): string
{
if ($column instanceof \Yiisoft\Db\Schema\Column\ArrayColumnSchema) {
if ($column instanceof \Yiisoft\Db\Schema\Column\ArrayColumn) {
return $this->buildType($column->getColumn()) . str_repeat('[]', $column->getDimension());
}

return parent::buildType($column);
}

protected function getDbType(ColumnSchemaInterface $column): string
protected function getDbType(ColumnInterface $column): string
{
/** @psalm-suppress DocblockTypeContradiction */
return $column->getDbType() ?? match ($column->getType()) {
Expand Down
32 changes: 16 additions & 16 deletions src/Column/ColumnFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Yiisoft\Db\Constraint\ForeignKeyConstraint;
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 preg_replace;
use function str_starts_with;
Expand All @@ -20,8 +20,8 @@
* @psalm-type ColumnInfo = array{
* auto_increment?: bool|string,
* check?: string|null,
* column?: ColumnSchemaInterface,
* columns?: array<string, ColumnSchemaInterface>,
* column?: ColumnInterface,
* columns?: array<string, ColumnInterface>,
* comment?: string|null,
* computed?: bool|string,
* db_type?: string|null,
Expand Down Expand Up @@ -119,11 +119,11 @@ final class ColumnFactory extends AbstractColumnFactory
'jsonb' => ColumnType::JSON,
];

public function fromType(string $type, array $info = []): ColumnSchemaInterface
public function fromType(string $type, array $info = []): ColumnInterface
{
$column = parent::fromType($type, $info);

if ($column instanceof StructuredColumnSchema) {
if ($column instanceof StructuredColumn) {
/** @psalm-var array|null $defaultValue */
$defaultValue = $column->getDefaultValue();

Expand All @@ -142,22 +142,22 @@ public function fromType(string $type, array $info = []): ColumnSchemaInterface
protected function getColumnClass(string $type, array $info = []): string
{
return match ($type) {
ColumnType::BOOLEAN => BooleanColumnSchema::class,
ColumnType::BIT => BitColumnSchema::class,
ColumnType::TINYINT => IntegerColumnSchema::class,
ColumnType::SMALLINT => IntegerColumnSchema::class,
ColumnType::INTEGER => IntegerColumnSchema::class,
ColumnType::BOOLEAN => BooleanColumn::class,
ColumnType::BIT => BitColumn::class,
ColumnType::TINYINT => IntegerColumn::class,
ColumnType::SMALLINT => IntegerColumn::class,
ColumnType::INTEGER => IntegerColumn::class,
ColumnType::BIGINT => PHP_INT_SIZE !== 8
? BigIntColumnSchema::class
: IntegerColumnSchema::class,
ColumnType::BINARY => BinaryColumnSchema::class,
ColumnType::ARRAY => ArrayColumnSchema::class,
ColumnType::STRUCTURED => StructuredColumnSchema::class,
? BigIntColumn::class
: IntegerColumn::class,
ColumnType::BINARY => BinaryColumn::class,
ColumnType::ARRAY => ArrayColumn::class,
ColumnType::STRUCTURED => StructuredColumn::class,
default => parent::getColumnClass($type, $info),
};
}

protected function normalizeNotNullDefaultValue(string $defaultValue, ColumnSchemaInterface $column): mixed
protected function normalizeNotNullDefaultValue(string $defaultValue, ColumnInterface $column): mixed
{
$value = preg_replace("/::[^:']+$/", '$1', $defaultValue);

Expand Down
12 changes: 12 additions & 0 deletions src/Column/IntegerColumn.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace Yiisoft\Db\Pgsql\Column;

use Yiisoft\Db\Schema\Column\IntegerColumn as BaseIntegerColumn;

final class IntegerColumn extends BaseIntegerColumn implements SequenceColumnInterface
{
use SequenceColumnTrait;
}
12 changes: 0 additions & 12 deletions src/Column/IntegerColumnSchema.php

This file was deleted.

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

namespace Yiisoft\Db\Pgsql\Column;

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

interface SequenceColumnSchemaInterface extends ColumnSchemaInterface
interface SequenceColumnInterface extends ColumnInterface
{
/**
* Returns name of an associated sequence if column is auto incremental.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Yiisoft\Db\Pgsql\Column;

trait SequenceColumnSchemaTrait
trait SequenceColumnTrait
{
/**
* @var string|null Name of an associated sequence if column is auto incremental.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
namespace Yiisoft\Db\Pgsql\Column;

use Yiisoft\Db\Pgsql\StructuredParser;
use Yiisoft\Db\Schema\Column\StructuredColumnSchema as BaseStructuredColumnSchema;
use Yiisoft\Db\Schema\Column\StructuredColumn as BaseStructuredColumn;
use Yiisoft\Db\Syntax\ParserToArrayInterface;

final class StructuredColumnSchema extends BaseStructuredColumnSchema
final class StructuredColumn extends BaseStructuredColumn
{
protected function getParser(): ParserToArrayInterface
{
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 Throwable;
use Yiisoft\Db\Exception\NotSupportedException;
use Yiisoft\Db\QueryBuilder\AbstractDDLQueryBuilder;
use Yiisoft\Db\Schema\Column\ColumnSchemaInterface;
use Yiisoft\Db\Schema\Column\ColumnInterface;

use function array_diff;
use function explode;
Expand All @@ -27,7 +27,7 @@ public function addDefaultValue(string $table, string $name, string $column, mix
throw new NotSupportedException(__METHOD__ . ' is not supported by PostgreSQL.');
}

public function alterColumn(string $table, string $column, ColumnSchemaInterface|string $type): string
public function alterColumn(string $table, string $column, ColumnInterface|string $type): string
{
$columnName = $this->quoter->quoteColumnName($column);
$tableName = $this->quoter->quoteTableName($table);
Expand Down
Loading