ColumnSchemaBuilder
extends ColumnSchemaBuilder
in package
ColumnSchemaBuilder is the schema builder for MySQL databases.
Tags
Table of Contents
Constants
- CATEGORY_NUMERIC = 'numeric'
- CATEGORY_OTHER = 'other'
- CATEGORY_PK = 'pk'
- CATEGORY_STRING = 'string'
- CATEGORY_TIME = 'time'
Properties
- $categoryMap : array<string|int, mixed>
- $comment : string
- $db : Connection
- $typeCategoryMap : array<string|int, mixed>
- $after : string
- $append : mixed
- $check : string
- $default : mixed
- $isFirst : bool
- $isNotNull : bool|null
- $isUnique : bool
- $isUnsigned : bool
- $length : int|string|array<string|int, mixed>
- $type : string
Methods
- __call() : mixed
- Calls the named method which is not a class method.
- __construct() : mixed
- Create a column schema builder instance giving the type and value precision.
- __get() : mixed
- Returns the value of an object property.
- __isset() : bool
- Checks if a property is set, i.e. defined and not null.
- __set() : mixed
- Sets value of an object property.
- __toString() : string
- Builds the full string for the column's schema.
- __unset() : mixed
- Sets an object property to null.
- after() : $this
- Adds an `AFTER` constraint to the column.
- append() : $this
- Specify additional SQL to be appended to column definition.
- canGetProperty() : bool
- Returns a value indicating whether a property can be read.
- canSetProperty() : bool
- Returns a value indicating whether a property can be set.
- check() : $this
- Sets a `CHECK` constraint for the column.
- className() : string
- Returns the fully qualified name of this class.
- comment() : $this
- Specifies the comment for column.
- defaultExpression() : $this
- Specify the default SQL expression for the column.
- defaultValue() : $this
- Specify the default value for the column.
- first() : $this
- Adds an `FIRST` constraint to the column.
- getCategoryMap() : array<string|int, mixed>
- hasMethod() : bool
- Returns a value indicating whether a method is defined.
- hasProperty() : bool
- Returns a value indicating whether a property is defined.
- init() : mixed
- Initializes the object.
- notNull() : $this
- Adds a `NOT NULL` constraint to the column.
- null() : $this
- Adds a `NULL` constraint to the column.
- setCategoryMap() : mixed
- unique() : $this
- Adds a `UNIQUE` constraint to the column.
- unsigned() : $this
- Marks column as unsigned.
- 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
- Returns the complete column definition from input format.
- buildDefaultString() : string
- Builds the default value specification for the column.
- buildDefaultValue() : string|null
- Return the default value 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.
Constants
CATEGORY_NUMERIC
public
mixed
CATEGORY_NUMERIC
= 'numeric'
CATEGORY_OTHER
public
mixed
CATEGORY_OTHER
= 'other'
CATEGORY_PK
public
mixed
CATEGORY_PK
= 'pk'
CATEGORY_STRING
public
mixed
CATEGORY_STRING
= 'string'
CATEGORY_TIME
public
mixed
CATEGORY_TIME
= 'time'
Properties
$categoryMap
public
array<string|int, mixed>
$categoryMap
Mapping of abstract column types (keys) to type categories (values).
$comment
public
string
$comment
comment value of the column.
Tags
$db
public
Connection
$db
the current database connection. It is used mainly to escape strings safely when building the final column schema string.
Tags
$typeCategoryMap
public
static array<string|int, mixed>
$typeCategoryMap
= [\yii\db\Schema::TYPE_PK => self::CATEGORY_PK, \yii\db\Schema::TYPE_UPK => self::CATEGORY_PK, \yii\db\Schema::TYPE_BIGPK => self::CATEGORY_PK, \yii\db\Schema::TYPE_UBIGPK => self::CATEGORY_PK, \yii\db\Schema::TYPE_CHAR => self::CATEGORY_STRING, \yii\db\Schema::TYPE_STRING => self::CATEGORY_STRING, \yii\db\Schema::TYPE_TEXT => self::CATEGORY_STRING, \yii\db\Schema::TYPE_TINYINT => self::CATEGORY_NUMERIC, \yii\db\Schema::TYPE_SMALLINT => self::CATEGORY_NUMERIC, \yii\db\Schema::TYPE_INTEGER => self::CATEGORY_NUMERIC, \yii\db\Schema::TYPE_BIGINT => self::CATEGORY_NUMERIC, \yii\db\Schema::TYPE_FLOAT => self::CATEGORY_NUMERIC, \yii\db\Schema::TYPE_DOUBLE => self::CATEGORY_NUMERIC, \yii\db\Schema::TYPE_DECIMAL => self::CATEGORY_NUMERIC, \yii\db\Schema::TYPE_DATETIME => self::CATEGORY_TIME, \yii\db\Schema::TYPE_TIMESTAMP => self::CATEGORY_TIME, \yii\db\Schema::TYPE_TIME => self::CATEGORY_TIME, \yii\db\Schema::TYPE_DATE => self::CATEGORY_TIME, \yii\db\Schema::TYPE_BINARY => self::CATEGORY_OTHER, \yii\db\Schema::TYPE_BOOLEAN => self::CATEGORY_NUMERIC, \yii\db\Schema::TYPE_MONEY => self::CATEGORY_NUMERIC]
mapping of abstract column types (keys) to type categories (values).
Tags
$after
protected
string
$after
the column after which this column will be added.
Tags
$append
protected
mixed
$append
SQL string to be appended to column schema definition.
Tags
$check
protected
string
$check
the CHECK
constraint for the column.
$default
protected
mixed
$default
default value of the column.
$isFirst
protected
bool
$isFirst
whether this column is to be inserted at the beginning of the table.
Tags
$isNotNull
protected
bool|null
$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
protected
bool
$isUnique
= false
whether the column values should be unique. If this is true
, a UNIQUE
constraint will be added.
$isUnsigned
protected
bool
$isUnsigned
= false
whether the column values should be unsigned. If this is true
, an UNSIGNED
keyword will be added.
Tags
$length
protected
int|string|array<string|int, mixed>
$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
protected
string
$type
the column type definition such as INTEGER, VARCHAR, DATETIME, etc.
Methods
__call()
Calls the named method which is not a class method.
public
__call(string $name, array<string|int, mixed> $params) : mixed
Do not call this method directly as it is a PHP magic method that will be implicitly called when an unknown method is being invoked.
Parameters
- $name : string
-
the method name
- $params : array<string|int, mixed>
-
method parameters
Tags
Return values
mixed —the method return value
__construct()
Create a column schema builder instance giving the type and value precision.
public
__construct(string $type[, int|string|array<string|int, mixed>|null $length = null ][, Connection|null $db = null ][, array<string|int, mixed> $config = [] ]) : mixed
Parameters
- $type : string
-
type of the column. See [[$type]].
- $length : int|string|array<string|int, mixed>|null = null
-
length or precision of the column. See [[$length]].
- $db : Connection|null = null
-
the current database connection. See [[$db]].
- $config : array<string|int, mixed> = []
-
name-value pairs that will be used to initialize the object properties
__get()
Returns the value of an object property.
public
__get(string $name) : mixed
Do not call this method directly as it is a PHP magic method that
will be implicitly called when executing $value = $object->property;
.
Parameters
- $name : string
-
the property name
Tags
Return values
mixed —the property value
__isset()
Checks if a property is set, i.e. defined and not null.
public
__isset(string $name) : bool
Do not call this method directly as it is a PHP magic method that
will be implicitly called when executing isset($object->property)
.
Note that if the property is not defined, false will be returned.
Parameters
- $name : string
-
the property name or the event name
Tags
Return values
bool —whether the named property is set (not null).
__set()
Sets value of an object property.
public
__set(string $name, mixed $value) : mixed
Do not call this method directly as it is a PHP magic method that
will be implicitly called when executing $object->property = $value;
.
Parameters
- $name : string
-
the property name or the event name
- $value : mixed
-
the property value
Tags
__toString()
Builds the full string for the column's schema.
public
__toString() : string
Return values
string__unset()
Sets an object property to null.
public
__unset(string $name) : mixed
Do not call this method directly as it is a PHP magic method that
will be implicitly called when executing unset($object->property)
.
Note that if the property is not defined, this method will do nothing. If the property is read-only, it will throw an exception.
Parameters
- $name : string
-
the property name
Tags
after()
Adds an `AFTER` constraint to the column.
public
after(string $after) : $this
Note: MySQL, Oracle and Cubrid support only.
Parameters
- $after : string
-
the column after which $this column will be added.
Tags
Return values
$thisappend()
Specify additional SQL to be appended to column definition.
public
append(string $sql) : $this
Position modifiers will be appended after column definition in databases that support them.
Parameters
- $sql : string
-
the SQL string to be appended.
Tags
Return values
$thiscanGetProperty()
Returns a value indicating whether a property can be read.
public
canGetProperty(string $name[, bool $checkVars = true ]) : bool
A property is readable if:
- the class has a getter method associated with the specified name (in this case, property name is case-insensitive);
- the class has a member variable with the specified name (when
$checkVars
is true);
Parameters
- $name : string
-
the property name
- $checkVars : bool = true
-
whether to treat member variables as properties
Tags
Return values
bool —whether the property can be read
canSetProperty()
Returns a value indicating whether a property can be set.
public
canSetProperty(string $name[, bool $checkVars = true ]) : bool
A property is writable if:
- the class has a setter method associated with the specified name (in this case, property name is case-insensitive);
- the class has a member variable with the specified name (when
$checkVars
is true);
Parameters
- $name : string
-
the property name
- $checkVars : bool = true
-
whether to treat member variables as properties
Tags
Return values
bool —whether the property can be written
check()
Sets a `CHECK` constraint for the column.
public
check(string $check) : $this
Parameters
- $check : string
-
the SQL of the
CHECK
constraint to be added.
Return values
$thisclassName()
Returns the fully qualified name of this class.
public
static className() : string
Tags
Return values
string —the fully qualified name of this class.
comment()
Specifies the comment for column.
public
comment(string $comment) : $this
Parameters
- $comment : string
-
the comment
Tags
Return values
$thisdefaultExpression()
Specify the default SQL expression for the column.
public
defaultExpression(string $default) : $this
Parameters
- $default : string
-
the default value expression.
Tags
Return values
$thisdefaultValue()
Specify the default value for the column.
public
defaultValue(mixed $default) : $this
Parameters
- $default : mixed
-
the default value.
Return values
$thisfirst()
Adds an `FIRST` constraint to the column.
public
first() : $this
Note: MySQL, Oracle and Cubrid support only.
Tags
Return values
$thisgetCategoryMap()
public
getCategoryMap() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —mapping of abstract column types (keys) to type categories (values).
hasMethod()
Returns a value indicating whether a method is defined.
public
hasMethod(string $name) : bool
The default implementation is a call to php function method_exists()
.
You may override this method when you implemented the php magic method __call()
.
Parameters
- $name : string
-
the method name
Return values
bool —whether the method is defined
hasProperty()
Returns a value indicating whether a property is defined.
public
hasProperty(string $name[, bool $checkVars = true ]) : bool
A property is defined if:
- the class has a getter or setter method associated with the specified name (in this case, property name is case-insensitive);
- the class has a member variable with the specified name (when
$checkVars
is true);
Parameters
- $name : string
-
the property name
- $checkVars : bool = true
-
whether to treat member variables as properties
Tags
Return values
bool —whether the property is defined
init()
Initializes the object.
public
init() : mixed
This method is invoked at the end of the constructor after the object is initialized with the given configuration.
notNull()
Adds a `NOT NULL` constraint to the column.
public
notNull() : $this
Return values
$thisnull()
Adds a `NULL` constraint to the column.
public
null() : $this
Tags
Return values
$thissetCategoryMap()
public
setCategoryMap(array<string|int, mixed> $categoryMap) : mixed
Parameters
- $categoryMap : array<string|int, mixed>
-
mapping of abstract column types (keys) to type categories (values).
Tags
unique()
Adds a `UNIQUE` constraint to the column.
public
unique() : $this
Return values
$thisunsigned()
Marks column as unsigned.
public
unsigned() : $this
Tags
Return values
$thisbuildAfterString()
Builds the after constraint for the column. Defaults to unsupported.
protected
buildAfterString() : string
Return values
string —a string containing the AFTER constraint.
buildAppendString()
Builds the custom string that's appended to column definition.
protected
buildAppendString() : string
Tags
Return values
string —custom string to append.
buildCheckString()
Builds the check constraint for the column.
protected
buildCheckString() : string
Return values
string —a string containing the CHECK constraint.
buildCommentString()
Builds the comment specification for the column.
protected
buildCommentString() : string
Return values
string —a string containing the COMMENT keyword and the comment itself
buildCompleteString()
Returns the complete column definition from input format.
protected
buildCompleteString(string $format) : string
Parameters
- $format : string
-
the format of the definition.
Tags
Return values
string —a string containing the complete column definition.
buildDefaultString()
Builds the default value specification for the column.
protected
buildDefaultString() : string
Return values
string —string with default value of column.
buildDefaultValue()
Return the default value for the column.
protected
buildDefaultValue() : string|null
Return values
string|null —string with default value of column.
buildFirstString()
Builds the first constraint for the column. Defaults to unsupported.
protected
buildFirstString() : string
Return values
string —a string containing the FIRST constraint.
buildLengthString()
Builds the length/precision part of the column.
protected
buildLengthString() : string
Return values
stringbuildNotNullString()
Builds the not null constraint for the column.
protected
buildNotNullString() : string
Return values
string —returns 'NOT NULL' if [[isNotNull]] is true, 'NULL' if [[isNotNull]] is false or an empty string otherwise.
buildUniqueString()
Builds the unique constraint for the column.
protected
buildUniqueString() : string
Return values
string —returns string 'UNIQUE' if [[isUnique]] is true, otherwise it returns an empty string.
buildUnsignedString()
Builds the unsigned string for column. Defaults to unsupported.
protected
buildUnsignedString() : string
Return values
string —a string containing UNSIGNED keyword.
getTypeCategory()
Returns the category of the column type.
protected
getTypeCategory() : string
Tags
Return values
string —a string containing the column type category name.