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

Remove ColumnInterface #335

Merged
merged 4 commits into from
Jan 8, 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 @@ -22,6 +22,7 @@
- Enh #331: Refactor according to changes #902 in `yiisoft/db` package (@Tigrov)
- Chg #333: Update `QueryBuilder` constructor (@Tigrov)
- Enh #332: Use `ColumnDefinitionBuilder` to generate table column SQL representation (@Tigrov)
- Enh #335: Remove `ColumnInterface` (@Tigrov)

## 1.2.0 March 21, 2024

Expand Down
43 changes: 0 additions & 43 deletions src/Column.php

This file was deleted.

7 changes: 1 addition & 6 deletions src/DDLQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use Yiisoft\Db\Exception\InvalidArgumentException;
use Yiisoft\Db\Exception\NotSupportedException;
use Yiisoft\Db\QueryBuilder\AbstractDDLQueryBuilder;
use Yiisoft\Db\Schema\Builder\ColumnInterface;
use Yiisoft\Db\Schema\Column\ColumnSchemaInterface;

use function array_diff;
Expand Down Expand Up @@ -53,16 +52,12 @@ public function addDefaultValue(string $table, string $name, string $column, mix
/**
* @throws Exception
*/
public function alterColumn(string $table, string $column, ColumnInterface|ColumnSchemaInterface|string $type): string
public function alterColumn(string $table, string $column, ColumnSchemaInterface|string $type): string
{
$columnName = $this->quoter->quoteColumnName($column);
$tableName = $this->quoter->quoteTableName($table);
$constraintBase = preg_replace('/\W/', '', $table . '_' . $column);

if ($type instanceof ColumnInterface) {
$type = $type->asString();
}

if (is_string($type)) {
$type = $this->schema->getColumnFactory()->fromDefinition($type);
}
Expand Down
45 changes: 0 additions & 45 deletions src/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,11 @@
namespace Yiisoft\Db\Mssql;

use Yiisoft\Db\Connection\ServerInfoInterface;
use Yiisoft\Db\Constant\ColumnType;
use Yiisoft\Db\Constant\PseudoType;
use Yiisoft\Db\Mssql\Column\ColumnDefinitionBuilder;
use Yiisoft\Db\QueryBuilder\AbstractQueryBuilder;
use Yiisoft\Db\Schema\Builder\ColumnInterface;
use Yiisoft\Db\Schema\QuoterInterface;
use Yiisoft\Db\Schema\SchemaInterface;

use function preg_replace;

/**
* Implements the MSSQL Server specific query builder.
*/
Expand All @@ -24,35 +19,6 @@ final class QueryBuilder extends AbstractQueryBuilder

protected const TRUE_VALUE = '1';

/**
* @psalm-var string[] $typeMap Mapping from abstract column types (keys) to physical column types (values).
*/
protected array $typeMap = [
PseudoType::PK => 'int IDENTITY PRIMARY KEY',
PseudoType::UPK => 'int IDENTITY PRIMARY KEY',
PseudoType::BIGPK => 'bigint IDENTITY PRIMARY KEY',
PseudoType::UBIGPK => 'bigint IDENTITY PRIMARY KEY',
ColumnType::CHAR => 'nchar(1)',
ColumnType::STRING => 'nvarchar(255)',
ColumnType::TEXT => 'nvarchar(max)',
ColumnType::TINYINT => 'tinyint',
ColumnType::SMALLINT => 'smallint',
ColumnType::INTEGER => 'int',
ColumnType::BIGINT => 'bigint',
ColumnType::FLOAT => 'float',
ColumnType::DOUBLE => 'float',
ColumnType::DECIMAL => 'decimal(18,0)',
ColumnType::DATETIME => 'datetime',
ColumnType::TIMESTAMP => 'datetime',
ColumnType::TIME => 'time',
ColumnType::DATE => 'date',
ColumnType::BINARY => 'varbinary(max)',
ColumnType::BOOLEAN => 'bit',
ColumnType::MONEY => 'decimal(19,4)',
ColumnType::UUID => 'UNIQUEIDENTIFIER',
PseudoType::UUID_PK => 'UNIQUEIDENTIFIER PRIMARY KEY',
];

public function __construct(QuoterInterface $quoter, SchemaInterface $schema, ServerInfoInterface $serverInfo)
{
parent::__construct(
Expand All @@ -65,15 +31,4 @@ public function __construct(QuoterInterface $quoter, SchemaInterface $schema, Se
new ColumnDefinitionBuilder($this),
);
}

/** @deprecated Use {@see buildColumnDefinition()}. Will be removed in version 2.0. */
public function getColumnType(ColumnInterface|string $type): string
{
/** @psalm-suppress DeprecatedMethod */
$columnType = parent::getColumnType($type);

/** remove unsupported keywords*/
$columnType = preg_replace("/\s*comment '.*'/i", '', $columnType);
return preg_replace('/ first$/i', '', $columnType);
}
}
8 changes: 0 additions & 8 deletions src/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use Yiisoft\Db\Exception\InvalidConfigException;
use Yiisoft\Db\Helper\DbArrayHelper;
use Yiisoft\Db\Mssql\Column\ColumnFactory;
use Yiisoft\Db\Schema\Builder\ColumnInterface;
use Yiisoft\Db\Schema\Column\ColumnFactoryInterface;
use Yiisoft\Db\Schema\Column\ColumnSchemaInterface;
use Yiisoft\Db\Schema\TableSchemaInterface;
Expand Down Expand Up @@ -68,13 +67,6 @@ final class Schema extends AbstractPdoSchema
*/
protected string|null $defaultSchema = 'dbo';

/** @deprecated Use {@see ColumnBuilder} instead. Will be removed in 2.0. */
public function createColumn(string $type, array|int|string|null $length = null): ColumnInterface
{
/** @psalm-suppress DeprecatedClass */
return new Column($type, $length);
}

public function getColumnFactory(): ColumnFactoryInterface
{
return new ColumnFactory();
Expand Down
18 changes: 0 additions & 18 deletions tests/ColumnSchemaBuilderTest.php

This file was deleted.

6 changes: 3 additions & 3 deletions tests/CommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use Yiisoft\Db\Exception\InvalidConfigException;
use Yiisoft\Db\Exception\NotSupportedException;
use Yiisoft\Db\Expression\Expression;
use Yiisoft\Db\Mssql\Column;
use Yiisoft\Db\Mssql\Column\ColumnBuilder;
use Yiisoft\Db\Mssql\Connection;
use Yiisoft\Db\Mssql\Dsn;
use Yiisoft\Db\Mssql\Driver;
Expand Down Expand Up @@ -336,8 +336,8 @@ public function testAlterColumnWithDefaultNull()
}

$command->createTable('column_with_constraint', ['id' => 'pk'])->execute();
$command->addColumn('column_with_constraint', 'field', (new Column('integer'))->null()->asString())->execute();
$command->alterColumn('column_with_constraint', 'field', (new Column('string', 40))->notNull()->asString())->execute();
$command->addColumn('column_with_constraint', 'field', ColumnBuilder::integer()->null())->execute();
$command->alterColumn('column_with_constraint', 'field', ColumnBuilder::string(40)->notNull())->execute();

$fieldCol = $db->getTableSchema('column_with_constraint', true)->getColumn('field');

Expand Down