0 follower

Final Class Yiisoft\Db\Mysql\Column\ColumnDefinitionBuilder

InheritanceYiisoft\Db\Mysql\Column\ColumnDefinitionBuilder » Yiisoft\Db\QueryBuilder\AbstractColumnDefinitionBuilder

Constants

Hide inherited constants

Constant Value Description Defined By
AUTO_INCREMENT_KEYWORD 'AUTO_INCREMENT' Yiisoft\Db\Mysql\Column\ColumnDefinitionBuilder
TYPES_WITH_SCALE [ 'float', 'real', 'double', 'double precision', 'decimal', 'numeric', 'dec', 'fixed', ] Yiisoft\Db\Mysql\Column\ColumnDefinitionBuilder
TYPES_WITH_SIZE [ 'bit', 'tinyint', 'smallint', 'mediumint', 'int', 'integer', 'bigint', 'float', 'real', 'double', 'double precision', 'decimal', 'numeric', 'dec', 'fixed', 'char', 'character', 'national char', 'nchar', 'varchar', 'character varying', 'national varchar', 'nvarchar', 'text', 'binary', 'char byte', 'varbinary', 'blob', 'year', 'timestamp', 'datetime', 'time', ] Yiisoft\Db\Mysql\Column\ColumnDefinitionBuilder

Method Details

Hide inherited methods

buildCheck() protected method

protected string buildCheck ( \Yiisoft\Db\Schema\Column\ColumnInterface $column )
$column \Yiisoft\Db\Schema\Column\ColumnInterface

                protected function buildCheck(ColumnInterface $column): string
{
    $check = $column->getCheck();
    if ($column instanceof EnumColumn && $column->getDbType() === null && empty($check)) {
        $dbType = $this->getDbType($column);
        if ($dbType === 'enum') {
            return '';
        }
    }
    return parent::buildCheck($column);
}

            
buildComment() protected method

protected string buildComment ( \Yiisoft\Db\Schema\Column\ColumnInterface $column )
$column \Yiisoft\Db\Schema\Column\ColumnInterface

                protected function buildComment(ColumnInterface $column): string
{
    $comment = $column->getComment();
    return $comment === null ? '' : ' COMMENT ' . $this->queryBuilder->getQuoter()->quoteValue($comment);
}

            
buildType() public method

public string buildType ( \Yiisoft\Db\Schema\Column\ColumnInterface $column )
$column \Yiisoft\Db\Schema\Column\ColumnInterface

                public function buildType(ColumnInterface $column): string
{
    if ($column instanceof EnumColumn) {
        $dbType = $this->getDbType($column);
        if (strtolower($dbType) === 'enum') {
            $values = array_map(
                $this->queryBuilder->getQuoter()->quoteValue(...),
                $column->getValues(),
            );
            return $dbType . '(' . implode(',', $values) . ')';
        }
    }
    $dbType = parent::buildType($column);
    if (!$column instanceof StringColumn || empty($column->getCharacterSet())) {
        return $dbType;
    }
    return "$dbType CHARACTER SET " . $column->getCharacterSet();
}

            
getDbType() protected method

protected string getDbType ( \Yiisoft\Db\Schema\Column\ColumnInterface $column )
$column \Yiisoft\Db\Schema\Column\ColumnInterface

                protected function getDbType(ColumnInterface $column): string
{
    /** @psalm-suppress DocblockTypeContradiction */
    $dbType = $column->getDbType() ?? match ($column->getType()) {
        ColumnType::BOOLEAN => 'bit(1)',
        ColumnType::BIT => 'bit',
        ColumnType::TINYINT => 'tinyint',
        ColumnType::SMALLINT => 'smallint',
        ColumnType::INTEGER => 'int',
        ColumnType::BIGINT => 'bigint',
        ColumnType::FLOAT => 'float',
        ColumnType::DOUBLE => 'double',
        ColumnType::DECIMAL => 'decimal',
        ColumnType::MONEY => 'decimal',
        ColumnType::CHAR => 'char',
        ColumnType::STRING => 'varchar(' . ($column->getSize() ?? 255) . ')',
        ColumnType::TEXT => 'text',
        ColumnType::BINARY => 'blob',
        ColumnType::UUID => 'binary(16)',
        ColumnType::TIMESTAMP => 'timestamp',
        ColumnType::DATETIME => 'datetime',
        ColumnType::DATETIMETZ => 'datetime',
        ColumnType::TIME => 'time',
        ColumnType::TIMETZ => 'time',
        ColumnType::DATE => 'date',
        ColumnType::ARRAY => 'json',
        ColumnType::STRUCTURED => 'json',
        ColumnType::JSON => 'json',
        ColumnType::ENUM => 'enum',
        default => 'varchar',
    };
    if ($dbType === 'double' && $column->getSize() !== null) {
        return 'double(' . $column->getSize() . ',' . ($column->getScale() ?? 0) . ')';
    }
    return $dbType;
}

            
getDefaultUuidExpression() protected method

protected string getDefaultUuidExpression ( )

                protected function getDefaultUuidExpression(): string
{
    $serverVersion = $this->queryBuilder->getServerInfo()->getVersion();
    if (!str_contains($serverVersion, 'MariaDB')
        && version_compare($serverVersion, '8', '<')
    ) {
        return '';
    }
    return "(unhex(replace(uuid(),'-','')))";
}