PHP Class yii\db\ColumnSchemaBuilder

See SchemaBuilderTrait for more detailed description and usage examples.
Since: 2.0.6
Author: Vasenin Matvey ([email protected])
Inheritance: extends yii\base\Object
Show file Open project: yiisoft/yii2

Public Properties

Property Type Description
$categoryMap mapping of abstract column types (keys) to type categories (values).
$comment comment value of the column.
$db the current database connection. It is used mainly to escape strings safely when building the final column schema string.

Protected Properties

Property Type Description
$after the column after which this column will be added.
$append SQL string to be appended to column schema definition.
$check the CHECK constraint for the column.
$default default value of the column.
$isFirst whether this column is to be inserted at the beginning of the table.
$isNotNull whether the column is or not nullable. If this is true, a NOT NULL constraint will be added. If this is false, a NULL constraint will be added.
$isUnique whether the column values should be unique. If this is true, a UNIQUE constraint will be added.
$isUnsigned whether the column values should be unsigned. If this is true, an UNSIGNED keyword will be added.
$length column size or precision definition. This is what goes into the parenthesis after the column type. This can be either a string, an integer or an array. If it is an array, the array values will be joined into a string separated by comma.
$type the column type definition such as INTEGER, VARCHAR, DATETIME, etc.

Public Methods

Method Description
__construct ( string $type, integer | string | array $length = null, Connection $db = null, array $config = [] ) Create a column schema builder instance giving the type and value precision.
__toString ( ) : string Builds the full string for the column's schema
after ( string $after ) Adds an AFTER constraint to the column.
append ( string $sql ) Specify additional SQL to be appended to schema string.
check ( string $check ) Sets a CHECK constraint for the column.
comment ( string $comment ) Specifies the comment for column.
defaultExpression ( string $default ) Specify the default SQL expression for the column.
defaultValue ( mixed $default ) Specify the default value for the column.
first ( ) Adds an FIRST constraint to the column.
notNull ( ) Adds a NOT NULL constraint to the column.
null ( ) Adds a NULL constraint to the column
unique ( ) Adds a UNIQUE constraint to the column.
unsigned ( ) Marks column as unsigned.

Protected Methods

Method Description
buildAfterString ( ) : string Builds the after constraint for the column. Defaults to unsupported.
buildAppendString ( ) : string Builds the custom string that's appended to column definition.
buildCheckString ( ) : string Builds the check constraint for the column.
buildCommentString ( ) : string Builds the comment specification for the column.
buildCompleteString ( string $format ) : string Returns the complete column definition from input format
buildDefaultString ( ) : string Builds the default value specification for the column.
buildFirstString ( ) : string Builds the first constraint for the column. Defaults to unsupported.
buildLengthString ( ) : string Builds the length/precision part of the column.
buildNotNullString ( ) : string Builds the not null constraint for the column.
buildUniqueString ( ) : string Builds the unique constraint for the column.
buildUnsignedString ( ) : string Builds the unsigned string for column. Defaults to unsupported.
getTypeCategory ( ) : string Returns the category of the column type.

Method Details

__construct() public method

Create a column schema builder instance giving the type and value precision.
public __construct ( string $type, integer | string | array $length = null, Connection $db = null, array $config = [] )
$type string type of the column. See [[$type]].
$length integer | string | array length or precision of the column. See [[$length]].
$db Connection the current database connection. See [[$db]].
$config array name-value pairs that will be used to initialize the object properties

__toString() public method

Builds the full string for the column's schema
public __toString ( ) : string
return string

after() public method

Note: MySQL, Oracle and Cubrid support only.
Since: 2.0.8
public after ( string $after )
$after string the column after which $this column will be added.

append() public method

Specify additional SQL to be appended to schema string.
Since: 2.0.9
public append ( string $sql )
$sql string the SQL string to be appended.

buildAfterString() protected method

Builds the after constraint for the column. Defaults to unsupported.
Since: 2.0.8
protected buildAfterString ( ) : string
return string a string containing the AFTER constraint.

buildAppendString() protected method

Builds the custom string that's appended to column definition.
Since: 2.0.9
protected buildAppendString ( ) : string
return string custom string to append.

buildCheckString() protected method

Builds the check constraint for the column.
protected buildCheckString ( ) : string
return string a string containing the CHECK constraint.

buildCommentString() protected method

Builds the comment specification for the column.
Since: 2.0.8
protected buildCommentString ( ) : string
return string a string containing the COMMENT keyword and the comment itself

buildCompleteString() protected method

Returns the complete column definition from input format
Since: 2.0.8
protected buildCompleteString ( string $format ) : string
$format string the format of the definition.
return string a string containing the complete column definition.

buildDefaultString() protected method

Builds the default value specification for the column.
protected buildDefaultString ( ) : string
return string string with default value of column.

buildFirstString() protected method

Builds the first constraint for the column. Defaults to unsupported.
Since: 2.0.8
protected buildFirstString ( ) : string
return string a string containing the FIRST constraint.

buildLengthString() protected method

Builds the length/precision part of the column.
protected buildLengthString ( ) : string
return string

buildNotNullString() protected method

Builds the not null constraint for the column.
protected buildNotNullString ( ) : string
return string returns 'NOT NULL' if [[isNotNull]] is true, 'NULL' if [[isNotNull]] is false or an empty string otherwise.

buildUniqueString() protected method

Builds the unique constraint for the column.
protected buildUniqueString ( ) : string
return string returns string 'UNIQUE' if [[isUnique]] is true, otherwise it returns an empty string.

buildUnsignedString() protected method

Builds the unsigned string for column. Defaults to unsupported.
Since: 2.0.7
protected buildUnsignedString ( ) : string
return string a string containing UNSIGNED keyword.

check() public method

Sets a CHECK constraint for the column.
public check ( string $check )
$check string the SQL of the `CHECK` constraint to be added.

comment() public method

Specifies the comment for column.
Since: 2.0.8
public comment ( string $comment )
$comment string the comment

defaultExpression() public method

Specify the default SQL expression for the column.
Since: 2.0.7
public defaultExpression ( string $default )
$default string the default value expression.

defaultValue() public method

Specify the default value for the column.
public defaultValue ( mixed $default )
$default mixed the default value.

first() public method

Note: MySQL, Oracle and Cubrid support only.
Since: 2.0.8
public first ( )

getTypeCategory() protected method

Returns the category of the column type.
Since: 2.0.8
protected getTypeCategory ( ) : string
return string a string containing the column type category name.

notNull() public method

Adds a NOT NULL constraint to the column.
public notNull ( )

null() public method

Adds a NULL constraint to the column
Since: 2.0.9
public null ( )

unique() public method

Adds a UNIQUE constraint to the column.
public unique ( )

unsigned() public method

Marks column as unsigned.
Since: 2.0.7
public unsigned ( )

Property Details

$after protected property

the column after which this column will be added.
Since: 2.0.8
protected $after

$append protected property

SQL string to be appended to column schema definition.
Since: 2.0.9
protected $append

$categoryMap public property

mapping of abstract column types (keys) to type categories (values).
Since: 2.0.8
public $categoryMap

$check protected property

the CHECK constraint for the column.
protected $check

$comment public property

comment value of the column.
Since: 2.0.8
public $comment

$db public property

the current database connection. It is used mainly to escape strings safely when building the final column schema string.
Since: 2.0.8
public $db

$default protected property

default value of the column.
protected $default

$isFirst protected property

whether this column is to be inserted at the beginning of the table.
Since: 2.0.8
protected $isFirst

$isNotNull protected property

whether the column is or not nullable. If this is true, a NOT NULL constraint will be added. If this is false, a NULL constraint will be added.
protected $isNotNull

$isUnique protected property

whether the column values should be unique. If this is true, a UNIQUE constraint will be added.
protected $isUnique

$isUnsigned protected property

whether the column values should be unsigned. If this is true, an UNSIGNED keyword will be added.
Since: 2.0.7
protected $isUnsigned

$length protected property

column size or precision definition. This is what goes into the parenthesis after the column type. This can be either a string, an integer or an array. If it is an array, the array values will be joined into a string separated by comma.
protected $length

$type protected property

the column type definition such as INTEGER, VARCHAR, DATETIME, etc.
protected $type