0 follower

Interface Yiisoft\Db\Schema\Column\ColumnInterface

Implemented byYiisoft\Db\Schema\Column\AbstractArrayColumn, Yiisoft\Db\Schema\Column\AbstractColumn, Yiisoft\Db\Schema\Column\AbstractJsonColumn, Yiisoft\Db\Schema\Column\AbstractStructuredColumn, Yiisoft\Db\Schema\Column\ArrayColumn, Yiisoft\Db\Schema\Column\ArrayLazyColumn, Yiisoft\Db\Schema\Column\BigIntColumn, Yiisoft\Db\Schema\Column\BinaryColumn, Yiisoft\Db\Schema\Column\BitColumn, Yiisoft\Db\Schema\Column\BooleanColumn, Yiisoft\Db\Schema\Column\DateTimeColumn, Yiisoft\Db\Schema\Column\DoubleColumn, Yiisoft\Db\Schema\Column\EnumColumn, Yiisoft\Db\Schema\Column\IntegerColumn, Yiisoft\Db\Schema\Column\JsonColumn, Yiisoft\Db\Schema\Column\JsonLazyColumn, Yiisoft\Db\Schema\Column\StringColumn, Yiisoft\Db\Schema\Column\StructuredColumn, Yiisoft\Db\Schema\Column\StructuredLazyColumn

This interface defines a set of methods that must be implemented by a class that represents a database table column.

Public Methods

Hide inherited methods

Method Description Defined By
autoIncrement() The database assigns auto incremented column a unique value automatically whenever you insert a new row into the table. This is useful for getting unique IDs for data such as customer or employee numbers. Yiisoft\Db\Schema\Column\ColumnInterface
check() The check constraint for the column to specify an expression that must be true for each row in the table. Yiisoft\Db\Schema\Column\ColumnInterface
comment() The comment for a column in a database table. Yiisoft\Db\Schema\Column\ColumnInterface
computed() A computed column is a virtual column that computes its values from an expression. Yiisoft\Db\Schema\Column\ColumnInterface
dbType() Sets a database data type for the column. Yiisoft\Db\Schema\Column\ColumnInterface
dbTypecast() Convert a value from its PHP representation to a database-specific representation. Yiisoft\Db\Schema\Column\ColumnInterface
defaultValue() A value that's automatically assigned to a column when you insert a new row into the database table. The default value can be a constant value, function, value derived from other columns, non-computed column name, or their combinations. Yiisoft\Db\Schema\Column\ColumnInterface
extra() Extra SQL to append to the generated SQL for a column. Yiisoft\Db\Schema\Column\ColumnInterface
getCheck() Returns the check constraint for the column. Yiisoft\Db\Schema\Column\ColumnInterface
getComment() Yiisoft\Db\Schema\Column\ColumnInterface
getDbType() Yiisoft\Db\Schema\Column\ColumnInterface
getDefaultValue() Yiisoft\Db\Schema\Column\ColumnInterface
getExtra() Yiisoft\Db\Schema\Column\ColumnInterface
getName() Yiisoft\Db\Schema\Column\ColumnInterface
getReference() Returns the reference to the foreign key constraint. Yiisoft\Db\Schema\Column\ColumnInterface
getScale() Yiisoft\Db\Schema\Column\ColumnInterface
getSize() Yiisoft\Db\Schema\Column\ColumnInterface
getType() Yiisoft\Db\Schema\Column\ColumnInterface
hasDefaultValue() Yiisoft\Db\Schema\Column\ColumnInterface
isAutoIncrement() Whether this column is auto incremental. Yiisoft\Db\Schema\Column\ColumnInterface
isComputed() Whether this column is computed. Yiisoft\Db\Schema\Column\ColumnInterface
isNotNull() Whether this column is not nullable. Yiisoft\Db\Schema\Column\ColumnInterface
isPrimaryKey() Whether this column is a part of primary key. Yiisoft\Db\Schema\Column\ColumnInterface
isUnique() Whether this column has a unique index. Yiisoft\Db\Schema\Column\ColumnInterface
isUnsigned() Whether this column is unsigned. This is only meaningful when type() is tinyint, smallint, integer or bigint. Yiisoft\Db\Schema\Column\ColumnInterface
notNull() Whether the column is not nullable. Yiisoft\Db\Schema\Column\ColumnInterface
null() Whether the column is nullable. Alias of notNull(false). Yiisoft\Db\Schema\Column\ColumnInterface
phpTypecast() Converts the input value after retrieval from the database. Yiisoft\Db\Schema\Column\ColumnInterface
primaryKey() The primary key is a column or set of columns that uniquely identifies each row in a table. Yiisoft\Db\Schema\Column\ColumnInterface
reference() The reference to the foreign key constraint. Yiisoft\Db\Schema\Column\ColumnInterface
scale() The scale is the number of digits to the right of the decimal point and is only meaningful when type() is decimal. Yiisoft\Db\Schema\Column\ColumnInterface
size() The size refers to the number of characters or digits allowed in a column of a database table. The size is typically used for character or numeric data types, such as VARCHAR, INT or DECIMAL, to specify the maximum length or precision of the data in the column. Yiisoft\Db\Schema\Column\ColumnInterface
type() The database type of the column. Yiisoft\Db\Schema\Column\ColumnInterface
unique() Whether the column has a unique index. Yiisoft\Db\Schema\Column\ColumnInterface
unsigned() Whether the column type is an unsigned integer. Yiisoft\Db\Schema\Column\ColumnInterface
withName() Returns a new instance with the specified name of the column. Yiisoft\Db\Schema\Column\ColumnInterface

Method Details

Hide inherited methods

autoIncrement() public abstract method

The database assigns auto incremented column a unique value automatically whenever you insert a new row into the table. This is useful for getting unique IDs for data such as customer or employee numbers.

You can set the autoIncrement for INTEGER or BIGINT data types.

If not set explicitly with this method call, the column isn't auto incremented.

$columns = [
    'id' => ColumnBuilder::primaryKey()->autoIncrement(),
];
public abstract autoIncrement( boolean $autoIncrement true ): Yiisoft\Db\Schema\Column\ColumnInterface
$autoIncrement boolean

                public function autoIncrement(bool $autoIncrement = true): static;

            
check() public abstract method

The check constraint for the column to specify an expression that must be true for each row in the table.

$columns = [
    'age' => ColumnBuilder::integer()->check('age > 0'),
];
public abstract check( string|null $check ): Yiisoft\Db\Schema\Column\ColumnInterface
$check string|null

                public function check(?string $check): static;

            
comment() public abstract method

The comment for a column in a database table.

The comment can give more information about the purpose or usage of the column.

$columns = [
    'description' => ColumnBuilder::text()->comment('Description of the product'),
];
public abstract comment( string|null $comment ): Yiisoft\Db\Schema\Column\ColumnInterface
$comment string|null

                public function comment(?string $comment): static;

            
computed() public abstract method

A computed column is a virtual column that computes its values from an expression.

If not set explicitly with this method call, the column isn't computed.

$columns = [
    'full_name' => ColumnBuilder::text()->computed(true),
];
public abstract computed( boolean $computed true ): Yiisoft\Db\Schema\Column\ColumnInterface
$computed boolean

                public function computed(bool $computed = true): static;

            
dbType() public abstract method

Sets a database data type for the column.

The data type can be one of the built-in data types supported by the database server (such as INTEGER, VARCHAR, DATETIME, etc.), a custom data type defined by the database server, or null if the database allows untyped columns.

$columns = [
    'description' => ColumnBuilder::text()->dbType('text'),
];
public abstract dbType( string|null $dbType ): Yiisoft\Db\Schema\Column\ColumnInterface
$dbType string|null

                public function dbType(?string $dbType): static;

            
dbTypecast() public abstract method

Convert a value from its PHP representation to a database-specific representation.

yiisoft/db calls it automatically by when preparing an SQL statement, so you don't usually need to call it directly in your code.

If the value is null or an \Yiisoft\Db\Schema\Column\Expression, there will be no conversion.

public abstract dbTypecast( mixed $value ): mixed
$value mixed
throws Yiisoft\Db\Exception\NotSupportedException

                public function dbTypecast(mixed $value): mixed;

            
defaultValue() public abstract method

A value that's automatically assigned to a column when you insert a new row into the database table. The default value can be a constant value, function, value derived from other columns, non-computed column name, or their combinations.

$columns = [
    'description' => ColumnBuilder::text()->defaultValue('Description of the product'),
];
public abstract defaultValue( mixed $defaultValue ): Yiisoft\Db\Schema\Column\ColumnInterface
$defaultValue mixed

                public function defaultValue(mixed $defaultValue): static;

            
extra() public abstract method

Extra SQL to append to the generated SQL for a column.

This can be useful for adding custom constraints or other SQL statements that aren't supported by the column schema itself.

$columns = [
    'updated_at' => ColumnBuilder::integer()->extra('ON UPDATE CURRENT_TIMESTAMP'),
];
public abstract extra( string|null $extra ): Yiisoft\Db\Schema\Column\ColumnInterface
$extra string|null

                public function extra(?string $extra): static;

            
getCheck() public abstract method

Returns the check constraint for the column.

See also check().

public abstract getCheck( ): string|null

                public function getCheck(): ?string;

            
getComment() public abstract method

See also comment().

public abstract getComment( ): string|null
return string|null

The comment of the column.

                public function getComment(): ?string;

            
getDbType() public abstract method

See also dbType().

public abstract getDbType( ): string|null
return string|null

The database data type of the column. Null means the column has no type in the database.

Note that the type includes size for columns supporting it, e.g. varchar(128). The size can be obtained separately via getSize().

                public function getDbType(): ?string;

            
getDefaultValue() public abstract method

See also defaultValue().

public abstract getDefaultValue( ): mixed
return mixed

The default value of the column.

                public function getDefaultValue(): mixed;

            
getExtra() public abstract method

See also extra().

public abstract getExtra( ): string|null
return string|null

The extra SQL for the column.

                public function getExtra(): ?string;

            
getName() public abstract method

public abstract getName( ): string|null
return string|null

The name of the column.

                public function getName(): ?string;

            
getReference() public abstract method

Returns the reference to the foreign key constraint.

See also reference().

public abstract getReference( ): Yiisoft\Db\Constraint\ForeignKey|null

                public function getReference(): ?ForeignKey;

            
getScale() public abstract method

See also scale().

public abstract getScale( ): integer|null
return integer|null

The scale of the column.

                public function getScale(): ?int;

            
getSize() public abstract method

See also size().

public abstract getSize( ): integer|null
return integer|null

The size of the column.

                public function getSize(): ?int;

            
getType() public abstract method

See also type().

public abstract getType( ): string
return string

The type of the column.

                public function getType(): string;

            
hasDefaultValue() public abstract method

public abstract hasDefaultValue( ): boolean

                public function hasDefaultValue(): bool;

            
isAutoIncrement() public abstract method

Whether this column is auto incremental.

This is only meaningful when type() is smallint, integer or bigint.

See also autoIncrement().

public abstract isAutoIncrement( ): boolean

                public function isAutoIncrement(): bool;

            
isComputed() public abstract method

Whether this column is computed.

See also computed().

public abstract isComputed( ): boolean

                public function isComputed(): bool;

            
isNotNull() public abstract method

Whether this column is not nullable.

See also notNull().

public abstract isNotNull( ): boolean|null

                public function isNotNull(): ?bool;

            
isPrimaryKey() public abstract method

Whether this column is a part of primary key.

See also primaryKey().

public abstract isPrimaryKey( ): boolean

                public function isPrimaryKey(): bool;

            
isUnique() public abstract method

Whether this column has a unique index.

See also unique().

public abstract isUnique( ): boolean

                public function isUnique(): bool;

            
isUnsigned() public abstract method

Whether this column is unsigned. This is only meaningful when type() is tinyint, smallint, integer or bigint.

See also unsigned().

public abstract isUnsigned( ): boolean

                public function isUnsigned(): bool;

            
notNull() public abstract method

Whether the column is not nullable.

$columns = [
    'description' => ColumnBuilder::text()->notNull(),
];
public abstract notNull( boolean $notNull true ): Yiisoft\Db\Schema\Column\ColumnInterface
$notNull boolean

                public function notNull(bool $notNull = true): static;

            
null() public abstract method

Whether the column is nullable. Alias of notNull(false).

public abstract null( ): Yiisoft\Db\Schema\Column\ColumnInterface

                public function null(): static;

            
phpTypecast() public abstract method

Converts the input value after retrieval from the database.

public abstract phpTypecast( mixed $value ): mixed
$value mixed
throws Yiisoft\Db\Exception\NotSupportedException

                public function phpTypecast(mixed $value): mixed;

            
primaryKey() public abstract method

The primary key is a column or set of columns that uniquely identifies each row in a table.

$columns = [
    'id' => ColumnBuilder::primaryKey(),
];
public abstract primaryKey( boolean $primaryKey true ): Yiisoft\Db\Schema\Column\ColumnInterface
$primaryKey boolean

                public function primaryKey(bool $primaryKey = true): static;

            
reference() public abstract method

The reference to the foreign key constraint.

$reference = new ForeignKeyConstraint();
$reference->foreignTableName('user');
$reference->foreignColumnNames(['id']);

$columns = [
    'user_id' => ColumnBuilder::integer()->reference($reference),
];
public abstract reference( Yiisoft\Db\Constraint\ForeignKey|null $reference ): Yiisoft\Db\Schema\Column\ColumnInterface
$reference Yiisoft\Db\Constraint\ForeignKey|null

                public function reference(?ForeignKey $reference): static;

            
scale() public abstract method

The scale is the number of digits to the right of the decimal point and is only meaningful when type() is decimal.

$columns = [
    'price' => ColumnBuilder::decimal(10, 2)->scale(2),
];
public abstract scale( integer|null $scale ): Yiisoft\Db\Schema\Column\ColumnInterface
$scale integer|null

                public function scale(?int $scale): static;

            
size() public abstract method

The size refers to the number of characters or digits allowed in a column of a database table. The size is typically used for character or numeric data types, such as VARCHAR, INT or DECIMAL, to specify the maximum length or precision of the data in the column.

$columns = [
    'name' => ColumnBuilder::string()->size(255),
];
public abstract size( integer|null $size ): Yiisoft\Db\Schema\Column\ColumnInterface
$size integer|null

                public function size(?int $size): static;

            
type() public abstract method

The database type of the column.

$columns = [
    'description' => ColumnBuilder::text()->type('text'),
];
public abstract type( string $type ): Yiisoft\Db\Schema\Column\ColumnInterface
$type string

                public function type(string $type): static;

            
unique() public abstract method

Whether the column has a unique index.

$columns = [
    'username' => ColumnBuilder::string()->unique(),
];
public abstract unique( boolean $unique true ): Yiisoft\Db\Schema\Column\ColumnInterface
$unique boolean

                public function unique(bool $unique = true): static;

            
unsigned() public abstract method

Whether the column type is an unsigned integer.

It's a data type that can only represent positive whole numbers only.

$columns = [
    'age' => ColumnBuilder::integer()->unsigned(),
];
public abstract unsigned( boolean $unsigned true ): Yiisoft\Db\Schema\Column\ColumnInterface
$unsigned boolean

                public function unsigned(bool $unsigned = true): static;

            
withName() public abstract method

Returns a new instance with the specified name of the column.

$columns = [
    'id' => ColumnBuilder::primaryKey()->withName('id'),
];
public abstract withName( string|null $name ): Yiisoft\Db\Schema\Column\ColumnInterface
$name string|null

                public function withName(?string $name): static;