Interface Yiisoft\Db\Schema\SchemaInterface
| Extends | Yiisoft\Db\Constraint\ConstraintSchemaInterface |
|---|---|
| Implemented by | Yiisoft\Db\Driver\Pdo\AbstractPdoSchema, Yiisoft\Db\Schema\AbstractSchema |
Represents the schema for a database table.
It provides a set of methods for working with the schema of a database table, such as accessing the columns, indexes, and constraints of a table, as well as methods for creating, dropping, and altering tables.
Public Methods
Constants
| Constant | Value | Description | Defined By |
|---|---|---|---|
| CHECKS | 'checks' | The metadata type for retrieving the check constraint. | Yiisoft\Db\Schema\SchemaInterface |
| DEFAULTS | 'defaults' | The metadata type for retrieving the default constraint. | Yiisoft\Db\Schema\SchemaInterface |
| DEFAULT_VALUES | 'defaultValues' | The metadata type for retrieving the default values constraint. | Yiisoft\Db\Schema\SchemaInterface |
| FOREIGN_KEYS | 'foreignKeys' | The metadata type for retrieving the foreign key constraints. | Yiisoft\Db\Schema\SchemaInterface |
| INDEXES | 'indexes' | The metadata type for retrieving the index constraints. | Yiisoft\Db\Schema\SchemaInterface |
| PRIMARY_KEY | 'primaryKey' | The metadata type for retrieving the primary key constraint. | Yiisoft\Db\Schema\SchemaInterface |
| SCHEMA | 'schema' | The metadata type for retrieving the table schema. | Yiisoft\Db\Schema\SchemaInterface |
| UNIQUES | 'uniques' | The metadata type for retrieving the unique constraints. | Yiisoft\Db\Schema\SchemaInterface |
Method Details
Enable or disable the schema cache.
| public abstract void enableCache ( boolean $value ) | ||
| $value | boolean |
Whether to enable or disable the schema cache. |
public function enableCache(bool $value): void;
Determines the SQL data type for the given PHP data value.
| public abstract integer getDataType ( mixed $data ) | ||
| $data | mixed |
The data to find a type for. |
| return | integer |
The type. |
|---|---|---|
public function getDataType(mixed $data): int;
| public abstract string getDefaultSchema ( ) | ||
| return | string |
The default schema name. |
|---|---|---|
public function getDefaultSchema(): string;
Returns the column instance for the column metadata received from the query result.
| public abstract Yiisoft\Db\Schema\Column\ColumnInterface|null getResultColumn ( array $metadata ) | ||
| $metadata | array |
The column metadata from the query result. |
public function getResultColumn(array $metadata): ?ColumnInterface;
Defined in: Yiisoft\Db\Constraint\ConstraintSchemaInterface::getSchemaChecks()
Returns check constraints for all tables in the database.
| public abstract Yiisoft\Db\Constraint\Check[] getSchemaChecks ( string $schema = '', boolean $refresh = false ) | ||
| $schema | string |
The schema of the tables. Defaults to empty string, meaning the current or default schema name. |
| $refresh | boolean |
Whether to fetch the latest available table schemas. If this is |
| return | Yiisoft\Db\Constraint\Check[] |
The check constraints for all tables in the database. |
|---|---|---|
public function getSchemaChecks(string $schema = '', bool $refresh = false): array;
Defined in: Yiisoft\Db\Constraint\ConstraintSchemaInterface::getSchemaDefaultValues()
Returns default value constraints for all tables in the database.
| public abstract Yiisoft\Db\Constraint\DefaultValue[] getSchemaDefaultValues ( string $schema = '', boolean $refresh = false ) | ||
| $schema | string |
The schema of the tables. Defaults to empty string, meaning the current or default schema name. |
| $refresh | boolean |
Whether to fetch the latest available table schemas. If this is |
| return | Yiisoft\Db\Constraint\DefaultValue[] |
The default value constraints for all tables in the database. |
|---|---|---|
public function getSchemaDefaultValues(string $schema = '', bool $refresh = false): array;
Defined in: Yiisoft\Db\Constraint\ConstraintSchemaInterface::getSchemaForeignKeys()
Returns foreign keys for all tables in the database.
| public abstract Yiisoft\Db\Constraint\ForeignKey[] getSchemaForeignKeys ( string $schema = '', boolean $refresh = false ) | ||
| $schema | string |
The schema of the tables. Defaults to empty string, meaning the current or default schema name. |
| $refresh | boolean |
Whether to fetch the latest available table schemas. If this is |
| return | Yiisoft\Db\Constraint\ForeignKey[] |
The foreign keys for all tables in the database. |
|---|---|---|
public function getSchemaForeignKeys(string $schema = '', bool $refresh = false): array;
Defined in: Yiisoft\Db\Constraint\ConstraintSchemaInterface::getSchemaIndexes()
Returns indexes for all tables in the database.
| public abstract Yiisoft\Db\Constraint\Index[] getSchemaIndexes ( string $schema = '', boolean $refresh = false ) | ||
| $schema | string |
The schema of the tables. Defaults to empty string, meaning the current or default schema name. |
| $refresh | boolean |
Whether to fetch the latest available table schemas. If this is false, cached data may be returned if available. |
| return | Yiisoft\Db\Constraint\Index[] |
The indexes for all tables in the database. |
|---|---|---|
public function getSchemaIndexes(string $schema = '', bool $refresh = false): array;
Returns all schema names in the database, except system schemas.
| public abstract string[] getSchemaNames ( boolean $refresh = false ) | ||
| $refresh | boolean |
Whether to fetch the latest available schema names. If this is |
| return | string[] |
All schemas name in the database, except system schemas. |
|---|---|---|
public function getSchemaNames(bool $refresh = false): array;
Defined in: Yiisoft\Db\Constraint\ConstraintSchemaInterface::getSchemaPrimaryKeys()
Returns primary keys for all tables in the database.
| public abstract Yiisoft\Db\Constraint\Index[] getSchemaPrimaryKeys ( string $schema = '', boolean $refresh = false ) | ||
| $schema | string |
The schema of the tables. Defaults to empty string, meaning the current or default schema name. |
| $refresh | boolean |
Whether to fetch the latest available table schemas. If this is |
| return | Yiisoft\Db\Constraint\Index[] |
The primary keys for all tables in the database. |
|---|---|---|
public function getSchemaPrimaryKeys(string $schema = '', bool $refresh = false): array;
Defined in: Yiisoft\Db\Constraint\ConstraintSchemaInterface::getSchemaUniques()
Returns unique constraints for all tables in the database.
| public abstract Yiisoft\Db\Constraint\Index[] getSchemaUniques ( string $schema = '', boolean $refresh = false ) | ||
| $schema | string |
The schema of the tables. Defaults to empty string, meaning the current or default schema name. |
| $refresh | boolean |
Whether to fetch the latest available table schemas. If this is |
| return | Yiisoft\Db\Constraint\Index[] |
The unique constraints for all tables in the database. |
|---|---|---|
public function getSchemaUniques(string $schema = '', bool $refresh = false): array;
Defined in: Yiisoft\Db\Constraint\ConstraintSchemaInterface::getTableChecks()
Obtains the check constraints' information for the named table.
| public abstract Yiisoft\Db\Constraint\Check[] getTableChecks ( string $name, boolean $refresh = false ) | ||
| $name | string |
Table name. The table name may contain a schema name if any. Don't quote the table name. |
| $refresh | boolean |
Whether to reload the information, even if it's found in the cache. |
| return | Yiisoft\Db\Constraint\Check[] |
The information metadata for the check constraints of the named table. |
|---|---|---|
public function getTableChecks(string $name, bool $refresh = false): array;
Defined in: Yiisoft\Db\Constraint\ConstraintSchemaInterface::getTableDefaultValues()
Obtains the default value constraints information for the named table.
| public abstract Yiisoft\Db\Constraint\DefaultValue[] getTableDefaultValues ( string $name, boolean $refresh = false ) | ||
| $name | string |
Table name. The table name may contain a schema name if any. Don't quote the table name. |
| $refresh | boolean |
Whether to reload the information, even if it's found in the cache. |
| return | Yiisoft\Db\Constraint\DefaultValue[] |
The information metadata for the default value constraints of the named table. |
|---|---|---|
public function getTableDefaultValues(string $name, bool $refresh = false): array;
Defined in: Yiisoft\Db\Constraint\ConstraintSchemaInterface::getTableForeignKeys()
Obtains the foreign keys' information for the named table.
| public abstract Yiisoft\Db\Constraint\ForeignKey[] getTableForeignKeys ( string $name, boolean $refresh = false ) | ||
| $name | string |
Table name. The table name may contain a schema name if any. Don't quote the table name. |
| $refresh | boolean |
Whether to reload the information, even if it's found in the cache. |
| return | Yiisoft\Db\Constraint\ForeignKey[] |
The information metadata for the foreign keys of the named table. |
|---|---|---|
public function getTableForeignKeys(string $name, bool $refresh = false): array;
Defined in: Yiisoft\Db\Constraint\ConstraintSchemaInterface::getTableIndexes()
Obtains the indexes' information for the named table.
| public abstract Yiisoft\Db\Constraint\Index[] getTableIndexes ( string $name, boolean $refresh = false ) | ||
| $name | string |
Table name. The table name may contain a schema name if any. Don't quote the table name. |
| $refresh | boolean |
Whether to reload the information, even if it's found in the cache. |
| return | Yiisoft\Db\Constraint\Index[] |
The information metadata for the indexes of the named table. |
|---|---|---|
public function getTableIndexes(string $name, bool $refresh = false): array;
Returns all table names in the database.
| public abstract string[] getTableNames ( string $schema = '', boolean $refresh = false ) | ||
| $schema | string |
The schema of the tables. Defaults to empty string, meaning the current or default schema name. If not empty, the returned table names will be prefixed with the schema name. |
| $refresh | boolean |
Whether to fetch the latest available table names. If this is |
| return | string[] |
All tables name in the database. |
|---|---|---|
public function getTableNames(string $schema = '', bool $refresh = false): array;
Defined in: Yiisoft\Db\Constraint\ConstraintSchemaInterface::getTablePrimaryKey()
Obtains the primary key for the named table.
| public abstract Yiisoft\Db\Constraint\Index|null getTablePrimaryKey ( string $name, boolean $refresh = false ) | ||
| $name | string |
Table name. The table name may contain a schema name if any. Don't quote the table name. |
| $refresh | boolean |
Whether to reload the information, even if it's found in the cache. |
| return | Yiisoft\Db\Constraint\Index|null |
The information metadata for the primary key of the named table. |
|---|---|---|
public function getTablePrimaryKey(string $name, bool $refresh = false): ?Index;
Obtains the metadata for the named table.
| public abstract Yiisoft\Db\Schema\TableSchemaInterface|null getTableSchema ( string $name, boolean $refresh = false ) | ||
| $name | string |
Table name. The table name may contain a schema name if any. Don't quote the table name. |
| $refresh | boolean |
Whether to reload the table schema even if it's found in the cache. |
| return | Yiisoft\Db\Schema\TableSchemaInterface|null |
Table metadata. |
|---|---|---|
public function getTableSchema(string $name, bool $refresh = false): ?TableSchemaInterface;
Returns the metadata for all tables in the database.
| public abstract Yiisoft\Db\Schema\TableSchemaInterface[] getTableSchemas ( string $schema = '', boolean $refresh = false ) | ||
| $schema | string |
The schema of the tables. Defaults to empty string, meaning the current or default schema name. |
| $refresh | boolean |
Whether to fetch the latest available table schemas. If this is |
| return | Yiisoft\Db\Schema\TableSchemaInterface[] |
The metadata for all tables in the database. |
|---|---|---|
public function getTableSchemas(string $schema = '', bool $refresh = false): array;
Defined in: Yiisoft\Db\Constraint\ConstraintSchemaInterface::getTableUniques()
Obtains the unique constraints' information for the named table.
| public abstract Yiisoft\Db\Constraint\Index[] getTableUniques ( string $name, boolean $refresh = false ) | ||
| $name | string |
Table name. The table name may contain a schema name if any. Don't quote the table name. |
| $refresh | boolean |
Whether to reload the information, even if it's found in the cache. |
| return | Yiisoft\Db\Constraint\Index[] |
The information metadata for the unique constraints of the named table. |
|---|---|---|
public function getTableUniques(string $name, bool $refresh = false): array;
Returns all view names in the database.
| public abstract string[] getViewNames ( string $schema = '', boolean $refresh = false ) | ||
| $schema | string |
The schema of the views. Defaults to empty string, meaning the current or default schema name. If not empty, the returned view names will be prefixed with the schema name. |
| $refresh | boolean |
Whether to fetch the latest available view names. If this is false, view names fetched before (if available) will be returned. |
| return | string[] |
All view names in the database. |
|---|---|---|
public function getViewNames(string $schema = '', bool $refresh = false): array;
Determines if a specified schema exists in the database.
| public abstract boolean hasSchema ( string $schema, boolean $refresh = false ) | ||
| $schema | string |
The schema name to search for |
| $refresh | boolean |
Whether to fetch the latest available schema names. If this is false, view names fetched before (if available) will be returned. |
| return | boolean |
Whether schema exists. |
|---|---|---|
public function hasSchema(string $schema, bool $refresh = false): bool;
Determines if a specified table exists in the database.
| public abstract boolean hasTable ( string $tableName, string $schema = '', boolean $refresh = false ) | ||
| $tableName | string |
The table name to search for |
| $schema | string |
The schema of the tables. Defaults to empty string, meaning the current or default schema name. If not empty, the table will be searched in the specified schema. |
| $refresh | boolean |
Whether to fetch the latest available table names. If this is false, view names fetched before (if available) will be returned. |
| return | boolean |
Whether table exists. |
|---|---|---|
public function hasTable(string $tableName, string $schema = '', bool $refresh = false): bool;
Determines if a specified view exists in the database.
| public abstract boolean hasView ( string $viewName, string $schema = '', boolean $refresh = false ) | ||
| $viewName | string |
The view name to search for |
| $schema | string |
The schema of the tables. Defaults to empty string, meaning the current or default schema name. If not empty, the table will be searched in the specified schema. |
| $refresh | boolean |
Whether to fetch the latest available view names. If this is false, view names fetched before (if available) will be returned. |
| return | boolean |
Whether view exists. |
|---|---|---|
public function hasView(string $viewName, string $schema = '', bool $refresh = false): bool;
Refreshes the schema.
This method cleans up all cached table schemas so that they can be re-created later to reflect the database schema change.
| public abstract void refresh ( ) |
public function refresh(): void;
Refreshes the particular table schema.
This method cleans up cached table schema so that it can be re-created later to reflect the database schema change.
| public abstract void refreshTableSchema ( string $name ) | ||
| $name | string |
Table name. |
public function refreshTableSchema(string $name): void;
Signup or Login in order to comment.