Interface TableSchemaInterface
An interface used by database TableSchema objects.
Constants summary
-
stringTYPE_BIGINTEGER'biginteger' -
stringTYPE_BINARY'binary' -
stringTYPE_BINARY_UUID'binaryuuid' -
stringTYPE_BOOLEAN'boolean' -
stringTYPE_DATE'date' -
stringTYPE_DATETIME'datetime' -
stringTYPE_DECIMAL'decimal' -
stringTYPE_FLOAT'float' -
stringTYPE_INTEGER'integer' -
stringTYPE_JSON'json' -
stringTYPE_SMALLINTEGER'smallinteger' -
stringTYPE_STRING'string' -
stringTYPE_TEXT'text' -
stringTYPE_TIME'time' -
stringTYPE_TIMESTAMP'timestamp' -
stringTYPE_TINYINTEGER'tinyinteger' -
stringTYPE_UUID'uuid'
Method Summary
- typeMap() public
Returns an array where the keys are the column names in the schema and the values the database type they have.
Method Detail
addColumn() public
addColumn(mixed $name, mixed $attrs)
Add a column to the table.
Attributes
Columns can have several attributes:
-
typeThe type of the column. This should be one of CakePHP's abstract types. -
lengthThe length of the column. -
precisionThe number of decimal places to store for float and decimal types. -
defaultThe default value of the column. -
nullWhether or not the column can hold nulls. -
fixedWhether or not the column is a fixed length column. This is only present/valid with string columns. -
unsignedWhether or not the column is an unsigned column. This is only present/valid for integer, decimal, float columns.
In addition to the above keys, the following keys are implemented in some database dialects, but not all:
-
commentThe comment for the column.
Parameters
-
string$name The name of the column
-
array|string$attrs The attributes for the column.
Returns
$thisaddConstraint() public
addConstraint(mixed $name, mixed $attrs)
Add a constraint.
Used to add constraints to a table. For example primary keys, unique keys and foreign keys.
Attributes
-
typeThe type of constraint being added. -
columnsThe columns in the index. -
referencesThe table, column a foreign key references. -
updateThe behavior on update. Options are 'restrict', 'setNull', 'cascade', 'noAction'. -
deleteThe behavior on delete. Options are 'restrict', 'setNull', 'cascade', 'noAction'.
The default for 'update' & 'delete' is 'cascade'.
Parameters
-
string$name The name of the constraint.
-
array$attrs The attributes for the constraint.
Returns
$thisaddIndex() public
addIndex(mixed $name, mixed $attrs)
Add an index.
Used to add indexes, and full text indexes in platforms that support them.
Attributes
-
typeThe type of index being added. -
columnsThe columns in the index.
Parameters
-
string$name The name of the index.
-
array$attrs The attributes for the index.
Returns
$thisbaseColumnType() public
baseColumnType(mixed $column)
Returns the base type name for the provided column.
This represent the database type a more complex class is based upon.
Parameters
-
string$column The column name to get the base type from
Returns
string|nullThe base type name
columns() public
columns()
Get the column names in the table.
Returns
string[]constraints() public
constraints()
Get the names of all the constraints in the table.
Returns
string[]defaultValues() public
defaultValues()
Get a hash of columns and their default values.
Returns
arraydropConstraint() public
dropConstraint(mixed $name)
Remove a constraint.
Parameters
-
string$name Name of the constraint to remove
Returns
$thisgetColumn() public
getColumn(mixed $name)
Get column data in the table.
Parameters
-
string$name The column name.
Returns
array|nullColumn data or null.
getColumnType() public
getColumnType(mixed $name)
Returns column type or null if a column does not exist.
Parameters
-
string$name The column to get the type of.
Returns
string|nullgetConstraint() public
getConstraint(mixed $name)
Read information about a constraint based on name.
Parameters
-
string$name The name of the constraint.
Returns
array|nullArray of constraint data, or null
getIndex() public
getIndex(mixed $name)
Read information about an index based on name.
Parameters
-
string$name The name of the index.
Returns
array|nullArray of index data, or null
getOptions() public
getOptions()
Gets the options for a table.
Table options allow you to set platform specific table level options. For example the engine type in MySQL.
Returns
arrayAn array of options.
hasAutoincrement() public
hasAutoincrement()
Check whether or not a table has an autoIncrement column defined.
Returns
boolhasColumn() public
hasColumn(mixed $name)
Returns true if a column exists in the schema.
Parameters
-
string$name Column name.
Returns
boolindexes() public
indexes()
Get the names of all the indexes in the table.
Returns
string[]isNullable() public
isNullable(mixed $name)
Check whether or not a field is nullable
Missing columns are nullable.
Parameters
-
string$name The column to get the type of.
Returns
boolWhether or not the field is nullable.
isTemporary() public
isTemporary()
Gets whether the table is temporary in the database.
Returns
boolThe current temporary setting.
name() public
name()
Get the name of the table.
Returns
stringprimaryKey() public
primaryKey()
Get the column(s) used for the primary key.
Returns
arrayColumn name(s) for the primary key. An empty list will be returned when the table has no primary key.
removeColumn() public
removeColumn(mixed $name)
Remove a column from the table schema.
If the column is not defined in the table, no error will be raised.
Parameters
-
string$name The name of the column
Returns
$thissetColumnType() public
setColumnType(mixed $name, mixed $type)
Sets the type of a column.
Parameters
-
string$name The column to set the type of.
-
string$type The type to set the column to.
Returns
$thissetOptions() public
setOptions(mixed $options)
Sets the options for a table.
Table options allow you to set platform specific table level options. For example the engine type in MySQL.
Parameters
-
array$options The options to set, or null to read options.
Returns
$thissetTemporary() public
setTemporary(mixed $temporary)
Sets whether the table is temporary in the database.
Parameters
-
bool$temporary Whether or not the table is to be temporary.
Returns
$thistypeMap() public
typeMap()
Returns an array where the keys are the column names in the schema and the values the database type they have.
Returns
array
© 2005–present The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
https://api.cakephp.org/3.9/interface-Cake.Database.Schema.TableSchemaInterface.html