SchemaDialect
in package
Base class for schema implementations.
This class contains methods that are common across the various SQL dialects.
Table of Contents
Properties
- $_driver : DriverInterface
- The driver instance being used.
Methods
- __construct() : mixed
- Constructor
- addConstraintSql() : array<string|int, mixed>
- Generate the SQL queries needed to add foreign key constraints to the table
- columnSql() : string
- Generate the SQL fragment for a single column in a table.
- constraintSql() : string
- Generate the SQL fragments for defining table constraints.
- convertColumnDescription() : void
- Convert field description results into abstract schema fields.
- convertForeignKeyDescription() : void
- Convert a foreign key description into constraints on the Table object.
- convertIndexDescription() : void
- Convert an index description results into abstract schema indexes or constraints.
- convertOptionsDescription() : void
- Convert options data into table options.
- createTableSql() : array<string|int, string>
- Generate the SQL to create a table.
- describeColumnSql() : array<string|int, mixed>
- Generate the SQL to describe a table.
- describeForeignKeySql() : array<string|int, mixed>
- Generate the SQL to describe the foreign keys in a table.
- describeIndexSql() : array<string|int, mixed>
- Generate the SQL to describe the indexes in a table.
- describeOptionsSql() : array<string|int, mixed>
- Generate the SQL to describe table options
- dropConstraintSql() : array<string|int, mixed>
- Generate the SQL queries needed to drop foreign key constraints from the table
- dropTableSql() : array<string|int, mixed>
- Generate the SQL to drop a table.
- indexSql() : string
- Generate the SQL fragment for a single index in a table.
- listTablesSql() : array<string|int, mixed>
- Generate the SQL to list the tables.
- listTablesWithoutViewsSql() : array<string|int, mixed>
- truncateTableSql() : array<string|int, mixed>
- Generate the SQL to truncate a table.
- _applyTypeSpecificColumnConversion() : array<string|int, mixed>|null
- Tries to use a matching database type to convert a SQL column definition to an abstract type definition.
- _convertConstraintColumns() : string
- Convert foreign key constraints references to a valid stringified list
- _convertOnClause() : string
- Convert string on clauses to the abstract ones.
- _foreignOnClause() : string
- Generate an ON clause for a foreign key.
- _getTypeSpecificColumnSql() : string|null
- Tries to use a matching database type to generate the SQL fragment for a single column in a table.
Properties
$_driver
The driver instance being used.
protected
DriverInterface
$_driver
Methods
__construct()
Constructor
public
__construct(DriverInterface $driver) : mixed
This constructor will connect the driver so that methods like columnSql() and others will fail when the driver has not been connected.
Parameters
- $driver : DriverInterface
-
The driver to use.
addConstraintSql()
Generate the SQL queries needed to add foreign key constraints to the table
public
abstract addConstraintSql(TableSchema $schema) : array<string|int, mixed>
Parameters
- $schema : TableSchema
-
The table instance the foreign key constraints are.
Return values
array<string|int, mixed> —SQL fragment.
columnSql()
Generate the SQL fragment for a single column in a table.
public
abstract columnSql(TableSchema $schema, string $name) : string
Parameters
- $schema : TableSchema
-
The table instance the column is in.
- $name : string
-
The name of the column.
Return values
string —SQL fragment.
constraintSql()
Generate the SQL fragments for defining table constraints.
public
abstract constraintSql(TableSchema $schema, string $name) : string
Parameters
- $schema : TableSchema
-
The table instance the column is in.
- $name : string
-
The name of the column.
Return values
string —SQL fragment.
convertColumnDescription()
Convert field description results into abstract schema fields.
public
abstract convertColumnDescription(TableSchema $schema, array<string|int, mixed> $row) : void
Parameters
- $schema : TableSchema
-
The table object to append fields to.
- $row : array<string|int, mixed>
-
The row data from
describeColumnSql
.
convertForeignKeyDescription()
Convert a foreign key description into constraints on the Table object.
public
abstract convertForeignKeyDescription(TableSchema $schema, array<string|int, mixed> $row) : void
Parameters
- $schema : TableSchema
-
The table object to append a constraint to.
- $row : array<string|int, mixed>
-
The row data from
describeForeignKeySql
.
convertIndexDescription()
Convert an index description results into abstract schema indexes or constraints.
public
abstract convertIndexDescription(TableSchema $schema, array<string|int, mixed> $row) : void
Parameters
- $schema : TableSchema
-
The table object to append an index or constraint to.
- $row : array<string|int, mixed>
-
The row data from
describeIndexSql
.
convertOptionsDescription()
Convert options data into table options.
public
convertOptionsDescription(TableSchema $schema, array<string|int, mixed> $row) : void
Parameters
- $schema : TableSchema
-
Table instance.
- $row : array<string|int, mixed>
-
The row of data.
createTableSql()
Generate the SQL to create a table.
public
abstract createTableSql(TableSchema $schema, array<string|int, string> $columns, array<string|int, string> $constraints, array<string|int, string> $indexes) : array<string|int, string>
Parameters
- $schema : TableSchema
-
Table instance.
- $columns : array<string|int, string>
-
The columns to go inside the table.
- $constraints : array<string|int, string>
-
The constraints for the table.
- $indexes : array<string|int, string>
-
The indexes for the table.
Return values
array<string|int, string> —SQL statements to create a table.
describeColumnSql()
Generate the SQL to describe a table.
public
abstract describeColumnSql(string $tableName, array<string, mixed> $config) : array<string|int, mixed>
Parameters
- $tableName : string
-
The table name to get information on.
- $config : array<string, mixed>
-
The connection configuration.
Return values
array<string|int, mixed> —An array of (sql, params) to execute.
describeForeignKeySql()
Generate the SQL to describe the foreign keys in a table.
public
abstract describeForeignKeySql(string $tableName, array<string, mixed> $config) : array<string|int, mixed>
Parameters
- $tableName : string
-
The table name to get information on.
- $config : array<string, mixed>
-
The connection configuration.
Return values
array<string|int, mixed> —An array of (sql, params) to execute.
describeIndexSql()
Generate the SQL to describe the indexes in a table.
public
abstract describeIndexSql(string $tableName, array<string, mixed> $config) : array<string|int, mixed>
Parameters
- $tableName : string
-
The table name to get information on.
- $config : array<string, mixed>
-
The connection configuration.
Return values
array<string|int, mixed> —An array of (sql, params) to execute.
describeOptionsSql()
Generate the SQL to describe table options
public
describeOptionsSql(string $tableName, array<string, mixed> $config) : array<string|int, mixed>
Parameters
- $tableName : string
-
Table name.
- $config : array<string, mixed>
-
The connection configuration.
Return values
array<string|int, mixed> —SQL statements to get options for a table.
dropConstraintSql()
Generate the SQL queries needed to drop foreign key constraints from the table
public
abstract dropConstraintSql(TableSchema $schema) : array<string|int, mixed>
Parameters
- $schema : TableSchema
-
The table instance the foreign key constraints are.
Return values
array<string|int, mixed> —SQL fragment.
dropTableSql()
Generate the SQL to drop a table.
public
dropTableSql(TableSchema $schema) : array<string|int, mixed>
Parameters
- $schema : TableSchema
-
Schema instance
Return values
array<string|int, mixed> —SQL statements to drop a table.
indexSql()
Generate the SQL fragment for a single index in a table.
public
abstract indexSql(TableSchema $schema, string $name) : string
Parameters
- $schema : TableSchema
-
The table object the column is in.
- $name : string
-
The name of the column.
Return values
string —SQL fragment.
listTablesSql()
Generate the SQL to list the tables.
public
abstract listTablesSql(array<string, mixed> $config) : array<string|int, mixed>
Parameters
- $config : array<string, mixed>
-
The connection configuration to use for getting tables from.
Return values
array<string|int, mixed> —An array of (sql, params) to execute.
listTablesWithoutViewsSql()
public
listTablesWithoutViewsSql([array<string|int, mixed> $config = ]) : array<string|int, mixed>
Generate the SQL to list the tables, excluding all views.
Parameters
- $config : array<string|int, mixed> =
Return values
array<string|int, mixed>truncateTableSql()
Generate the SQL to truncate a table.
public
abstract truncateTableSql(TableSchema $schema) : array<string|int, mixed>
Parameters
- $schema : TableSchema
-
Table instance.
Return values
array<string|int, mixed> —SQL statements to truncate a table.
_applyTypeSpecificColumnConversion()
Tries to use a matching database type to convert a SQL column definition to an abstract type definition.
protected
_applyTypeSpecificColumnConversion(string $columnType, array<string|int, mixed> $definition) : array<string|int, mixed>|null
Parameters
- $columnType : string
-
The column type.
- $definition : array<string|int, mixed>
-
The column definition.
Return values
array<string|int, mixed>|null —Array of column information, or null
in case no corresponding type was found or the type
didn't provide custom column information.
_convertConstraintColumns()
Convert foreign key constraints references to a valid stringified list
protected
_convertConstraintColumns(array<string|int, string>|string $references) : string
Parameters
- $references : array<string|int, string>|string
-
The referenced columns of a foreign key constraint statement
Return values
string_convertOnClause()
Convert string on clauses to the abstract ones.
protected
_convertOnClause(string $clause) : string
Parameters
- $clause : string
-
The on clause to convert.
Return values
string_foreignOnClause()
Generate an ON clause for a foreign key.
protected
_foreignOnClause(string $on) : string
Parameters
- $on : string
-
The on clause
Return values
string_getTypeSpecificColumnSql()
Tries to use a matching database type to generate the SQL fragment for a single column in a table.
protected
_getTypeSpecificColumnSql(string $columnType, TableSchemaInterface $schema, string $column) : string|null
Parameters
- $columnType : string
-
The column type.
- $schema : TableSchemaInterface
-
The table schema instance the column is in.
- $column : string
-
The name of the column.
Return values
string|null —An SQL fragment, or null
in case no corresponding type was found or the type didn't provide
custom column SQL.