An interface used by TableSchema objects.
Add a column to the table.
Returns the base type name for the provided column. This represent the database type a more complex class is based upon.
Get the column names in the table.
Get a hash of columns and their default values.
Get column data in the table.
Returns column type or null if a column does not exist.
Gets the options for a table.
Returns true if a column exists in the schema.
Check whether a field is nullable
Get the name of the table.
Remove a column from the table schema.
Sets the type of a column.
Sets the options for a table.
Returns an array where the keys are the column names in the schema and the values the database type they have.
addColumn(string $name, array<string, mixed>|string $attrs): $this
Add a column to the table.
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.string
$name The name of the column
array<string, mixed>|string
$attrs The attributes for the column or the type name.
$this
baseColumnType(string $column): string|null
Returns the base type name for the provided column. This represent the database type a more complex class is based upon.
string
$column The column name to get the base type from
string|null
columns(): array<string>
Get the column names in the table.
array<string>
defaultValues(): array<string, mixed>
Get a hash of columns and their default values.
array<string, mixed>
getColumn(string $name): array<string, mixed>|null
Get column data in the table.
string
$name The column name.
array<string, mixed>|null
getColumnType(string $name): string|null
Returns column type or null if a column does not exist.
string
$name The column to get the type of.
string|null
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.
array<string, mixed>
hasColumn(string $name): bool
Returns true if a column exists in the schema.
string
$name Column name.
bool
isNullable(string $name): bool
Check whether a field is nullable
Missing columns are nullable.
string
$name The column to get the type of.
bool
name(): string
Get the name of the table.
string
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.
string
$name The name of the column
$this
setColumnType(string $name, string $type): $this
Sets the type of a column.
string
$name The column to set the type of.
string
$type The type to set the column to.
$this
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.
array<string, mixed>
$options The options to set, or null to read options.
$this
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.
array<string, string>
© 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/4.4/interface-Cake.Datasource.SchemaInterface.html