0 follower

Class Yiisoft\Db\Schema\Column\ColumnBuilder

InheritanceYiisoft\Db\Schema\Column\ColumnBuilder

Column builder for database Yiisoft\Db\Schema\Column\ColumnInterface instances.

Public Methods

Hide inherited methods

Method Description Defined By
array() Builds a column with the abstract type array. Yiisoft\Db\Schema\Column\ColumnBuilder
bigPrimaryKey() Builds a column as a bigint primary key. Yiisoft\Db\Schema\Column\ColumnBuilder
bigint() Builds a column with the abstract type bigint. Yiisoft\Db\Schema\Column\ColumnBuilder
binary() Builds a column with the abstract type binary. Yiisoft\Db\Schema\Column\ColumnBuilder
bit() Builds a column with the abstract type bit. Yiisoft\Db\Schema\Column\ColumnBuilder
boolean() Builds a column with the abstract type boolean. Yiisoft\Db\Schema\Column\ColumnBuilder
char() Builds a column with the abstract type char. Yiisoft\Db\Schema\Column\ColumnBuilder
date() Builds a column with the abstract type date. Yiisoft\Db\Schema\Column\ColumnBuilder
datetime() Builds a column with the abstract type datetime. Yiisoft\Db\Schema\Column\ColumnBuilder
datetimeWithTimezone() Builds a column with the abstract type datetimetz. Yiisoft\Db\Schema\Column\ColumnBuilder
decimal() Builds a column with the abstract type decimal. Yiisoft\Db\Schema\Column\ColumnBuilder
double() Builds a column with the abstract type double. Yiisoft\Db\Schema\Column\ColumnBuilder
enum() Builds a column with the abstract type enum. Yiisoft\Db\Schema\Column\ColumnBuilder
float() Builds a column with the abstract type float. Yiisoft\Db\Schema\Column\ColumnBuilder
integer() Builds a column with the abstract type integer. Yiisoft\Db\Schema\Column\ColumnBuilder
json() Builds a column with the abstract type json. Yiisoft\Db\Schema\Column\ColumnBuilder
money() Builds a column with the abstract type money. Yiisoft\Db\Schema\Column\ColumnBuilder
primaryKey() Builds a column as an integer primary key. Yiisoft\Db\Schema\Column\ColumnBuilder
smallPrimaryKey() Builds a column as a smallint primary key. Yiisoft\Db\Schema\Column\ColumnBuilder
smallint() Builds a column with the abstract type smallint. Yiisoft\Db\Schema\Column\ColumnBuilder
string() Builds a column with the abstract type string. Yiisoft\Db\Schema\Column\ColumnBuilder
structured() Builds a column with the abstract type structured. Yiisoft\Db\Schema\Column\ColumnBuilder
text() Builds a column with the abstract type text. Yiisoft\Db\Schema\Column\ColumnBuilder
time() Builds a column with the abstract type time. Yiisoft\Db\Schema\Column\ColumnBuilder
timeWithTimezone() Builds a column with the abstract type timetz. Yiisoft\Db\Schema\Column\ColumnBuilder
timestamp() Builds a column with the abstract type timestamp. Yiisoft\Db\Schema\Column\ColumnBuilder
tinyint() Builds a column with the abstract type tinyint. Yiisoft\Db\Schema\Column\ColumnBuilder
uuid() Builds a column with the abstract type uuid. Yiisoft\Db\Schema\Column\ColumnBuilder
uuidPrimaryKey() Builds a column as an uuid primary key. Yiisoft\Db\Schema\Column\ColumnBuilder

Method Details

Hide inherited methods

array() public static method

Builds a column with the abstract type array.

public static array( Yiisoft\Db\Schema\Column\ColumnInterface|null $column null ): Yiisoft\Db\Schema\Column\ColumnInterface
$column Yiisoft\Db\Schema\Column\ColumnInterface|null

The instance of Yiisoft\Db\Schema\Column\ColumnInterface of the array elements.

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

            
bigPrimaryKey() public static method

Builds a column as a bigint primary key.

public static bigPrimaryKey( boolean $autoIncrement true ): Yiisoft\Db\Schema\Column\ColumnInterface
$autoIncrement boolean

                public static function bigPrimaryKey(bool $autoIncrement = true): ColumnInterface
{
    return static::bigint()
        ->primaryKey()
        ->autoIncrement($autoIncrement);
}

            
bigint() public static method

Builds a column with the abstract type bigint.

public static bigint( integer|null $size null, boolean $unsigned false ): Yiisoft\Db\Schema\Column\ColumnInterface
$size integer|null
$unsigned boolean

                public static function bigint(?int $size = null, bool $unsigned = false): ColumnInterface
{
    return PHP_INT_SIZE === 4 || $unsigned
        ? new BigIntColumn(ColumnType::BIGINT, size: $size, unsigned: $unsigned)
        : new IntegerColumn(ColumnType::BIGINT, size: $size, unsigned: $unsigned);
}

            
binary() public static method

Builds a column with the abstract type binary.

public static binary( integer|null $size null ): Yiisoft\Db\Schema\Column\ColumnInterface
$size integer|null

                public static function binary(?int $size = null): ColumnInterface
{
    return new BinaryColumn(ColumnType::BINARY, size: $size);
}

            
bit() public static method

Builds a column with the abstract type bit.

public static bit( integer|null $size null ): Yiisoft\Db\Schema\Column\ColumnInterface
$size integer|null

The number of bits that the column can store.

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

            
boolean() public static method

Builds a column with the abstract type boolean.

public static boolean( ): Yiisoft\Db\Schema\Column\ColumnInterface

                public static function boolean(): ColumnInterface
{
    return new BooleanColumn(ColumnType::BOOLEAN);
}

            
char() public static method

Builds a column with the abstract type char.

public static char( integer|null $size 1 ): Yiisoft\Db\Schema\Column\ColumnInterface
$size integer|null

                public static function char(?int $size = 1): ColumnInterface
{
    return new StringColumn(ColumnType::CHAR, size: $size);
}

            
date() public static method

Builds a column with the abstract type date.

public static date( ): Yiisoft\Db\Schema\Column\ColumnInterface

                public static function date(): ColumnInterface
{
    return new DateTimeColumn(ColumnType::DATE);
}

            
datetime() public static method

Builds a column with the abstract type datetime.

public static datetime( integer|null $size 0 ): Yiisoft\Db\Schema\Column\ColumnInterface
$size integer|null

                public static function datetime(?int $size = 0): ColumnInterface
{
    return new DateTimeColumn(ColumnType::DATETIME, size: $size);
}

            
datetimeWithTimezone() public static method

Builds a column with the abstract type datetimetz.

public static datetimeWithTimezone( integer|null $size 0 ): Yiisoft\Db\Schema\Column\ColumnInterface
$size integer|null

                public static function datetimeWithTimezone(?int $size = 0): ColumnInterface
{
    return new DateTimeColumn(ColumnType::DATETIMETZ, size: $size);
}

            
decimal() public static method

Builds a column with the abstract type decimal.

public static decimal( integer|null $size 10, integer|null $scale 0 ): Yiisoft\Db\Schema\Column\ColumnInterface
$size integer|null
$scale integer|null

                public static function decimal(?int $size = 10, ?int $scale = 0): ColumnInterface
{
    return new DoubleColumn(ColumnType::DECIMAL, scale: $scale, size: $size);
}

            
double() public static method

Builds a column with the abstract type double.

public static double( integer|null $size null, integer|null $scale null ): Yiisoft\Db\Schema\Column\ColumnInterface
$size integer|null
$scale integer|null

                public static function double(?int $size = null, ?int $scale = null): ColumnInterface
{
    return new DoubleColumn(ColumnType::DOUBLE, scale: $scale, size: $size);
}

            
enum() public static method

Builds a column with the abstract type enum.

public static enum( string[]|null $values null, string|null $dbType null ): Yiisoft\Db\Schema\Column\EnumColumn
$values string[]|null

The list of possible values for the enum column.

$dbType string|null

The database type of the column. When null, the column will use a CHECK constraint.

                public static function enum(?array $values = null, ?string $dbType = null): EnumColumn
{
    return new EnumColumn(dbType: $dbType, values: $values);
}

            
float() public static method

Builds a column with the abstract type float.

public static float( integer|null $size null, integer|null $scale null ): Yiisoft\Db\Schema\Column\ColumnInterface
$size integer|null
$scale integer|null

                public static function float(?int $size = null, ?int $scale = null): ColumnInterface
{
    return new DoubleColumn(ColumnType::FLOAT, scale: $scale, size: $size);
}

            
integer() public static method

Builds a column with the abstract type integer.

public static integer( integer|null $size null ): Yiisoft\Db\Schema\Column\ColumnInterface
$size integer|null

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

            
json() public static method

Builds a column with the abstract type json.

public static json( ): Yiisoft\Db\Schema\Column\ColumnInterface

                public static function json(): ColumnInterface
{
    return new JsonColumn(ColumnType::JSON);
}

            
money() public static method

Builds a column with the abstract type money.

public static money( integer|null $size 19, integer|null $scale 4 ): Yiisoft\Db\Schema\Column\ColumnInterface
$size integer|null
$scale integer|null

                public static function money(?int $size = 19, ?int $scale = 4): ColumnInterface
{
    return new DoubleColumn(ColumnType::MONEY, scale: $scale, size: $size);
}

            
primaryKey() public static method

Builds a column as an integer primary key.

public static primaryKey( boolean $autoIncrement true ): Yiisoft\Db\Schema\Column\ColumnInterface
$autoIncrement boolean

                public static function primaryKey(bool $autoIncrement = true): ColumnInterface
{
    return static::integer()
        ->primaryKey()
        ->autoIncrement($autoIncrement);
}

            
smallPrimaryKey() public static method

Builds a column as a smallint primary key.

public static smallPrimaryKey( boolean $autoIncrement true ): Yiisoft\Db\Schema\Column\ColumnInterface
$autoIncrement boolean

                public static function smallPrimaryKey(bool $autoIncrement = true): ColumnInterface
{
    return static::smallint()
        ->primaryKey()
        ->autoIncrement($autoIncrement);
}

            
smallint() public static method

Builds a column with the abstract type smallint.

public static smallint( integer|null $size null ): Yiisoft\Db\Schema\Column\ColumnInterface
$size integer|null

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

            
string() public static method

Builds a column with the abstract type string.

public static string( integer|null $size 255 ): Yiisoft\Db\Schema\Column\ColumnInterface
$size integer|null

                public static function string(?int $size = 255): ColumnInterface
{
    return new StringColumn(ColumnType::STRING, size: $size);
}

            
structured() public static method

Builds a column with the abstract type structured.

public static structured( string|null $dbType null, Yiisoft\Db\Schema\Column\ColumnInterface[] $columns = [] ): Yiisoft\Db\Schema\Column\ColumnInterface
$dbType string|null

The DB type of the column.

$columns Yiisoft\Db\Schema\Column\ColumnInterface[]

The columns (name -> instance) that the structured column should contain.

                public static function structured(?string $dbType = null, array $columns = []): ColumnInterface
{
    return new StructuredColumn(ColumnType::STRUCTURED, dbType: $dbType, columns: $columns);
}

            
text() public static method

Builds a column with the abstract type text.

public static text( integer|null $size null ): Yiisoft\Db\Schema\Column\ColumnInterface
$size integer|null

The maximum length of the column or null if it is not limited.

MySQL creates the column as the smallest TEXT type large enough to hold values of $size characters. This corresponds to TINYTEXT, MEDIUMTEXT, TEXT, and LONGTEXT column types and depends on the character set used.

For example, the maximum sizes in different character sets are as follows: | Column type | latin1 | utf8 | utf8mb4 |-------------|---------------|---------------|---------------- | TINYTEXT | 255 | 85 | 63 | TEXT | 65,535 | 21,845 | 16,383 | MEDIUMTEXT | 16,777,215 | 5,592,405 | 4,194,303 | LONGTEXT | 4,294,967,295 | 4,294,967,295 | 4,294,967,295

                public static function text(?int $size = null): ColumnInterface
{
    return new StringColumn(ColumnType::TEXT, size: $size);
}

            
time() public static method

Builds a column with the abstract type time.

public static time( integer|null $size 0 ): Yiisoft\Db\Schema\Column\ColumnInterface
$size integer|null

                public static function time(?int $size = 0): ColumnInterface
{
    return new DateTimeColumn(ColumnType::TIME, size: $size);
}

            
timeWithTimezone() public static method

Builds a column with the abstract type timetz.

public static timeWithTimezone( integer|null $size 0 ): Yiisoft\Db\Schema\Column\ColumnInterface
$size integer|null

                public static function timeWithTimezone(?int $size = 0): ColumnInterface
{
    return new DateTimeColumn(ColumnType::TIMETZ, size: $size);
}

            
timestamp() public static method

Builds a column with the abstract type timestamp.

public static timestamp( integer|null $size 0 ): Yiisoft\Db\Schema\Column\ColumnInterface
$size integer|null

                public static function timestamp(?int $size = 0): ColumnInterface
{
    return new DateTimeColumn(ColumnType::TIMESTAMP, size: $size);
}

            
tinyint() public static method

Builds a column with the abstract type tinyint.

public static tinyint( integer|null $size null ): Yiisoft\Db\Schema\Column\ColumnInterface
$size integer|null

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

            
uuid() public static method

Builds a column with the abstract type uuid.

public static uuid( ): Yiisoft\Db\Schema\Column\ColumnInterface

                public static function uuid(): ColumnInterface
{
    return new StringColumn(ColumnType::UUID);
}

            
uuidPrimaryKey() public static method

Builds a column as an uuid primary key.

public static uuidPrimaryKey( boolean $autoIncrement true ): Yiisoft\Db\Schema\Column\ColumnInterface
$autoIncrement boolean

                public static function uuidPrimaryKey(bool $autoIncrement = true): ColumnInterface
{
    return static::uuid()
        ->primaryKey()
        ->autoIncrement($autoIncrement);
}