diff --git a/CHANGELOG.md b/CHANGELOG.md index 30f7185b..48a2be36 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,8 @@ ## 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 + for type casting performance. Related with yiisoft/db#752 (@Tigrov) ## 1.2.0 March 21, 2024 @@ -17,8 +19,6 @@ - Enh #263: Support json type (@Tigrov) - Enh #278: Move methods from `Command` to `AbstractPdoCommand` class (@Tigrov) - Bug #268: Fix foreign keys: support multiple foreign keys referencing to one table and possible null columns for reference (@Tigrov) -- Enh #273: Implement `ColumnSchemaInterface` classes according to the data type of database table columns - for type casting performance. Related with yiisoft/db#752 (@Tigrov) - Bug #271: Refactor `DMLQueryBuilder`, related with yiisoft/db#746 (@Tigrov) ## 1.0.1 July 24, 2023 diff --git a/src/ColumnSchema.php b/src/ColumnSchema.php deleted file mode 100644 index 043ce5a9..00000000 --- a/src/ColumnSchema.php +++ /dev/null @@ -1,94 +0,0 @@ -name('id'); - * $column->allowNull(false); - * $column->dbType('integer'); - * $column->phpType('integer'); - * $column->type('integer'); - * $column->defaultValue(0); - * $column->autoIncrement(true); - * $column->primaryKey(true); - * ``` - * - * @psalm-suppress DeprecatedInterface - * @psalm-suppress DeprecatedClass - */ -final class ColumnSchema extends AbstractColumnSchema -{ - /** - * Converts a value from its PHP representation to a database-specific representation. - * - * If the value is null or an {@see Expression}, it won't be converted. - * - * @param mixed $value The value to be converted. - * - * @return mixed The converted value. - */ - public function dbTypecast(mixed $value): mixed - { - if ($value === null || $value instanceof ExpressionInterface) { - return $value; - } - - if ($this->getType() === SchemaInterface::TYPE_JSON) { - return new JsonExpression($value, $this->getDbType()); - } - - /** @psalm-suppress DeprecatedClass */ - return parent::dbTypecast($value); - } - - /** - * Converts the input value according to {@see phpType} after retrieval from the database. - * - * If the value is null or an {@see Expression}, it won't be converted. - * - * @param mixed $value The value to be converted. - * - * @throws JsonException - * @return mixed The converted value. - */ - public function phpTypecast(mixed $value): mixed - { - if ($value === null) { - return null; - } - - if ($this->getType() === SchemaInterface::TYPE_JSON) { - return json_decode((string) $value, true, 512, JSON_THROW_ON_ERROR); - } - - /** @psalm-suppress DeprecatedClass */ - return parent::phpTypecast($value); - } -} diff --git a/src/Schema.php b/src/Schema.php index 43817018..bc3c7a26 100644 --- a/src/Schema.php +++ b/src/Schema.php @@ -373,10 +373,10 @@ protected function findColumns(TableSchemaInterface $table): bool } $column = $this->loadColumnSchema($info); - $table->column($column->getName(), $column); + $table->column($info['name'], $column); if ($column->isPrimaryKey()) { - $table->primaryKey($column->getName()); + $table->primaryKey($info['name']); } } @@ -488,7 +488,6 @@ private function loadColumnSchema(array $info): ColumnSchemaInterface $column->allowNull(!$info['notnull']); $column->primaryKey((bool) $info['pk']); $column->dbType($dbType); - $column->phpType($this->getColumnPhpType($type)); $column->defaultValue($this->normalizeDefaultValue($info['dflt_value'], $column)); return $column;