Interface SchemaInterface
An interface used by TableSchema objects.
Method Summary
-
addColumn() public
Add a column to the table.
-
baseColumnType() public
Returns the base type name for the provided column. This represents the database type a more complex class is based upon.
-
columns() public
Get the column names in the table.
-
defaultValues() public
Get a hash of columns and their default values.
-
getColumn() public
Get column data in the table.
-
getColumnType() public
Returns column type or null if a column does not exist.
-
getOptions() public
Gets the options for a table.
-
hasColumn() public
Returns true if a column exists in the schema.
-
isNullable() public
Check whether a field is nullable
-
name() public
Get the name of the table.
-
removeColumn() public
Remove a column from the table schema.
-
setColumnType() public
Sets the type of column.
-
setOptions() public
Sets the options for a table.
-
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(string $name, array<string, mixed>|string $attrs): $this
Add a column to the table.
Attributes
Columns can have several attributes:
type
The type of the column. This should be one of CakePHP's abstract types.length
The length of the column.precision
The number of decimal places to store for float and decimal types.default
The default value of the column.null
Whether the column can hold nulls.fixed
Whether the column is a fixed length column. This is only present/valid with string columns.unsigned
Whether 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:
comment
The comment for the column.
Parameters
-
string
$name The name of the column
-
array<string, mixed>|string
$attrs The attributes for the column or the type name.
Returns
$this
baseColumnType() ¶ public
baseColumnType(string $column): string|null
Returns the base type name for the provided column. This represents the database type a more complex class is based upon.
Parameters
-
string
$column The column name to get the base type from
Returns
string|null
columns() ¶ public
columns(): array<string>
Get the column names in the table.
Returns
array<string>
defaultValues() ¶ public
defaultValues(): array<string, mixed>
Get a hash of columns and their default values.
Returns
array<string, mixed>
getColumn() ¶ public
getColumn(string $name): array<string, mixed>|null
Get column data in the table.
Parameters
-
string
$name The column name.
Returns
array<string, mixed>|null
getColumnType() ¶ public
getColumnType(string $name): string|null
Returns column type or null if a column does not exist.
Parameters
-
string
$name The column to get the type of.
Returns
string|null
getOptions() ¶ public
getOptions(): array<string, mixed>
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
array<string, mixed>
hasColumn() ¶ public
hasColumn(string $name): bool
Returns true if a column exists in the schema.
Parameters
-
string
$name Column name.
Returns
bool
isNullable() ¶ public
isNullable(string $name): bool
Check whether a field is nullable
Missing columns are nullable.
Parameters
-
string
$name The column to get the type of.
Returns
bool
removeColumn() ¶ public
removeColumn(string $name): $this
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
$this
setColumnType() ¶ public
setColumnType(string $name, string $type): $this
Sets the type of column.
Parameters
-
string
$name The column to set the type of.
-
string
$type The type to set the column to.
Returns
$this
setOptions() ¶ public
setOptions(array<string, mixed> $options): $this
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<string, mixed>
$options The options to set, or null to read options.
Returns
$this
typeMap() ¶ public
typeMap(): array<string, string>
Returns an array where the keys are the column names in the schema and the values the database type they have.
Returns
array<string, string>