Abstract Class Yiisoft\Db\Driver\Pdo\AbstractPdoSchema
| Inheritance | Yiisoft\Db\Driver\Pdo\AbstractPdoSchema » Yiisoft\Db\Schema\AbstractSchema |
|---|---|
| Implements | Yiisoft\Db\Schema\SchemaInterface |
Represents a schema for a PDO (PHP Data Object) connection.
Protected Properties
| Property | Type | Description | Defined By |
|---|---|---|---|
| $db | Yiisoft\Db\Connection\ConnectionInterface | Yiisoft\Db\Schema\AbstractSchema | |
| $defaultSchema | string | The default schema name used for the current session. | Yiisoft\Db\Schema\AbstractSchema |
| $resultColumns | (Yiisoft\Db\Schema\Column\ColumnInterface|null)[] | Saved columns from query results. | Yiisoft\Db\Schema\AbstractSchema |
| $viewNames | string[][] | Yiisoft\Db\Schema\AbstractSchema |
Public Methods
Protected Methods
| Method | Description | Defined By |
|---|---|---|
| clearFullName() | Clears the full name. Removes the schema name if it is the default schema name, removes curly brackets from the name, and replaces the percentage character '%' with Yiisoft\Db\Connection\ConnectionInterface::getTablePrefix(). | Yiisoft\Db\Schema\AbstractSchema |
| findConstraints() | Find and initialize table constraints. | Yiisoft\Db\Schema\AbstractSchema |
| findSchemaNames() | Returns all schema names in the database, including the default one but not system schemas. | Yiisoft\Db\Schema\AbstractSchema |
| findTableNames() | Returns all table names in the database. | Yiisoft\Db\Schema\AbstractSchema |
| findViewNames() | Find the view names for the database. | Yiisoft\Db\Schema\AbstractSchema |
| generateCacheKey() | Generates the cache key for the current connection. | Yiisoft\Db\Driver\Pdo\AbstractPdoSchema |
| getCacheKey() | Yiisoft\Db\Driver\Pdo\AbstractPdoSchema | |
| getCacheTag() | Yiisoft\Db\Driver\Pdo\AbstractPdoSchema | |
| getResultColumnCacheKey() | Yiisoft\Db\Driver\Pdo\AbstractPdoSchema | |
| getSchemaMetadata() | Returns the metadata of the given type for all tables in the given schema. | Yiisoft\Db\Schema\AbstractSchema |
| getTableMetadata() | Returns the metadata of the given type for the given table. | Yiisoft\Db\Schema\AbstractSchema |
| getTableTypeMetadata() | This method returns the desired metadata type for table name (with refresh if needed). | Yiisoft\Db\Schema\AbstractSchema |
| loadResultColumn() | Creates a new column instance according to the column metadata received from the query result. | Yiisoft\Db\Schema\AbstractSchema |
| loadTableChecks() | Loads all check constraints for the given table. | Yiisoft\Db\Schema\AbstractSchema |
| loadTableDefaultValues() | Loads all default value constraints for the given table. | Yiisoft\Db\Schema\AbstractSchema |
| loadTableForeignKeys() | Loads all foreign keys for the given table. | Yiisoft\Db\Schema\AbstractSchema |
| loadTableIndexes() | Loads all indexes for the given table. | Yiisoft\Db\Schema\AbstractSchema |
| loadTableSchema() | Loads the metadata for the specified table. | Yiisoft\Db\Schema\AbstractSchema |
| loadTableTypeMetadata() | This method returns the desired metadata type for the table name. | Yiisoft\Db\Schema\AbstractSchema |
| resolveFullName() | Resolves the full table name, considering the default schema name. Removes curly brackets from the names, and replaces the percentage character '%' with Yiisoft\Db\Connection\ConnectionInterface::getTablePrefix(). | Yiisoft\Db\Schema\AbstractSchema |
| setTableMetadata() | Sets the metadata of the given type for the given table. | Yiisoft\Db\Schema\AbstractSchema |
Constants
| Constant | Value | Description | Defined By |
|---|---|---|---|
| CACHE_VERSION | 'cacheVersion' | Yiisoft\Db\Schema\AbstractSchema | |
| 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 |
| SCHEMA_CACHE_VERSION | 1 | Schema cache version, to detect incompatibilities in cached values when the data format of the cache changes. | Yiisoft\Db\Schema\AbstractSchema |
| UNIQUES | 'uniques' | The metadata type for retrieving the unique constraints. | Yiisoft\Db\Schema\SchemaInterface |
Method Details
Defined in: Yiisoft\Db\Schema\AbstractSchema::__construct()
| public __construct( Yiisoft\Db\Connection\ConnectionInterface $db, Yiisoft\Db\Cache\SchemaCache $schemaCache ): mixed | ||
| $db | Yiisoft\Db\Connection\ConnectionInterface | |
| $schemaCache | Yiisoft\Db\Cache\SchemaCache | |
public function __construct(
protected ConnectionInterface $db,
private readonly SchemaCache $schemaCache,
) {}
Defined in: Yiisoft\Db\Schema\AbstractSchema::clearFullName()
Clears the full name. Removes the schema name if it is the default schema name, removes curly brackets from the name, and replaces the percentage character '%' with Yiisoft\Db\Connection\ConnectionInterface::getTablePrefix().
| protected clearFullName( string $fullName ): string | ||
| $fullName | string | |
protected function clearFullName(string $fullName): string
{
return $this->resolveFullName(...$this->db->getQuoter()->getTableNameParts($fullName));
}
Defined in: Yiisoft\Db\Schema\AbstractSchema::enableCache()
| public enableCache( boolean $value ): void | ||
| $value | boolean | |
public function enableCache(bool $value): void
{
$this->schemaCache->setEnabled($value);
}
Defined in: Yiisoft\Db\Schema\AbstractSchema::findConstraints()
Find and initialize table constraints.
| protected findConstraints( Yiisoft\Db\Schema\TableSchemaInterface $table ): void | ||
| $table | Yiisoft\Db\Schema\TableSchemaInterface |
The table metadata. |
protected function findConstraints(TableSchemaInterface $table): void
{
$tableName = $this->resolveFullName($table->getName(), $table->getSchemaName());
$table->checks(...$this->getTableMetadata($tableName, SchemaInterface::CHECKS));
$table->defaultValues(...$this->getTableMetadata($tableName, SchemaInterface::DEFAULT_VALUES));
$table->foreignKeys(...$this->getTableMetadata($tableName, SchemaInterface::FOREIGN_KEYS));
$table->indexes(...$this->getTableMetadata($tableName, SchemaInterface::INDEXES));
}
Defined in: Yiisoft\Db\Schema\AbstractSchema::findSchemaNames()
Returns all schema names in the database, including the default one but not system schemas.
This method should be overridden by child classes to support this feature because the default implementation simply throws an exception.
| protected findSchemaNames( ): string[] | ||
| return | string[] |
All schemas name in the database, except system schemas. |
|---|---|---|
| throws | Yiisoft\Db\Exception\NotSupportedException |
If the DBMS doesn't support this method. |
protected function findSchemaNames(): array
{
throw new NotSupportedException(static::class . ' does not support fetching all schema names.');
}
Defined in: Yiisoft\Db\Schema\AbstractSchema::findTableNames()
Returns all table names in the database.
This method should be overridden by child classes to support this feature because the default implementation simply throws an exception.
| protected findTableNames( string $schema ): string[] | ||
| $schema | string |
The schema of the tables. Defaults to empty string, meaning the current or default schema. |
| return | string[] |
All tables name in the database. The names have NO schema name prefix. |
|---|---|---|
| throws | Yiisoft\Db\Exception\NotSupportedException |
If the DBMS doesn't support this method. |
protected function findTableNames(string $schema): array
{
throw new NotSupportedException(static::class . ' does not support fetching all table names.');
}
Defined in: Yiisoft\Db\Schema\AbstractSchema::findViewNames()
Find the view names for the database.
| protected findViewNames( string $schema = '' ): string[] | ||
| $schema | string |
The schema of the views. Defaults to empty string, meaning the current or default schema. |
| return | string[] |
The names of all views in the database. |
|---|---|---|
protected function findViewNames(string $schema = ''): array
{
return [];
}
Generates the cache key for the current connection.
| protected generateCacheKey( ): array | ||
| return | array |
The cache key. |
|---|---|---|
| throws | Yiisoft\Db\Exception\NotSupportedException |
If the connection is not a PDO connection. |
protected function generateCacheKey(): array
{
if ($this->db instanceof PdoConnectionInterface) {
$cacheKey = [$this->db->getDriver()->getDsn(), $this->db->getDriver()->getUsername()];
} else {
throw new NotSupportedException('Only PDO connections are supported.');
}
return $cacheKey;
}
| protected getCacheKey( string $name ): array | ||
| $name | string | |
protected function getCacheKey(string $name): array
{
return [static::class, ...$this->generateCacheKey(), $name];
}
| protected getCacheTag( ): string |
protected function getCacheTag(): string
{
return md5(serialize([static::class, ...$this->generateCacheKey()]));
}
Defined in: Yiisoft\Db\Schema\AbstractSchema::getDataType()
| public getDataType( mixed $data ): integer | ||
| $data | mixed | |
public function getDataType(mixed $data): int
{
return match (gettype($data)) {
// php type => SQL data type
GettypeResult::BOOLEAN => DataType::BOOLEAN,
GettypeResult::INTEGER => DataType::INTEGER,
GettypeResult::RESOURCE => DataType::LOB,
GettypeResult::NULL => DataType::NULL,
default => DataType::STRING,
};
}
| public getDefaultSchema( ): string |
public function getDefaultSchema(): string
{
return $this->defaultSchema;
}
| public getResultColumn( array $metadata ): Yiisoft\Db\Schema\Column\ColumnInterface|null | ||
| $metadata | array | |
final public function getResultColumn(array $metadata): ?ColumnInterface
{
if (empty($metadata)) {
return null;
}
$cacheKey = $this->getResultColumnCacheKey($metadata);
if (array_key_exists($cacheKey, $this->resultColumns)) {
return $this->resultColumns[$cacheKey];
}
$isCacheEnabled = $this->schemaCache->isEnabled();
if ($isCacheEnabled) {
/** @var ColumnInterface */
$this->resultColumns[$cacheKey] = $this->schemaCache->get($cacheKey);
if (isset($this->resultColumns[$cacheKey])) {
return $this->resultColumns[$cacheKey];
}
}
$column = $this->loadResultColumn($metadata);
$this->resultColumns[$cacheKey] = $column;
if ($column !== null && $isCacheEnabled) {
$this->schemaCache->set($cacheKey, $column, $this->getCacheTag());
}
return $column;
}
| protected getResultColumnCacheKey( array $metadata ): string | ||
| $metadata | array | |
protected function getResultColumnCacheKey(array $metadata): string
{
return md5(serialize([static::class . '::getResultColumn', ...$this->generateCacheKey(), ...$metadata]));
}
| public getSchemaChecks( string $schema = '', boolean $refresh = false ): array | ||
| $schema | string | |
| $refresh | boolean | |
public function getSchemaChecks(string $schema = '', bool $refresh = false): array
{
/** @var Check[] */
return $this->getSchemaMetadata($schema, SchemaInterface::CHECKS, $refresh);
}
| public getSchemaDefaultValues( string $schema = '', boolean $refresh = false ): array | ||
| $schema | string | |
| $refresh | boolean | |
public function getSchemaDefaultValues(string $schema = '', bool $refresh = false): array
{
/** @var DefaultValue[] */
return $this->getSchemaMetadata($schema, SchemaInterface::DEFAULT_VALUES, $refresh);
}
| public getSchemaForeignKeys( string $schema = '', boolean $refresh = false ): array | ||
| $schema | string | |
| $refresh | boolean | |
public function getSchemaForeignKeys(string $schema = '', bool $refresh = false): array
{
/** @var ForeignKey[] */
return $this->getSchemaMetadata($schema, SchemaInterface::FOREIGN_KEYS, $refresh);
}
| public getSchemaIndexes( string $schema = '', boolean $refresh = false ): array | ||
| $schema | string | |
| $refresh | boolean | |
public function getSchemaIndexes(string $schema = '', bool $refresh = false): array
{
/** @var Index[] */
return $this->getSchemaMetadata($schema, SchemaInterface::INDEXES, $refresh);
}
Defined in: Yiisoft\Db\Schema\AbstractSchema::getSchemaMetadata()
Returns the metadata of the given type for all tables in the given schema.
| protected getSchemaMetadata( string $schema, string $type, boolean $refresh ): Yiisoft\Db\Constraint\Check[][]|Yiisoft\Db\Constraint\DefaultValue[][]|Yiisoft\Db\Constraint\ForeignKey[][]|Yiisoft\Db\Constraint\Index[]|Yiisoft\Db\Constraint\Index[][]|Yiisoft\Db\Schema\TableSchemaInterface[] | ||
| $schema | string |
The schema of the metadata. Defaults to empty string, meaning the current or default schema name. |
| $type | string |
The metadata type. |
| $refresh | boolean |
Whether to fetch the latest available table metadata. If this is |
| return | Yiisoft\Db\Constraint\Check[][]|Yiisoft\Db\Constraint\DefaultValue[][]|Yiisoft\Db\Constraint\ForeignKey[][]|Yiisoft\Db\Constraint\Index[]|Yiisoft\Db\Constraint\Index[][]|Yiisoft\Db\Schema\TableSchemaInterface[] |
The metadata of the given type for all tables in the given schema. |
|---|---|---|
protected function getSchemaMetadata(string $schema, string $type, bool $refresh): array
{
$metadata = [];
$quoter = $this->db->getQuoter();
$tableNames = $this->getTableNames($schema, $refresh);
foreach ($tableNames as $name) {
$name = $quoter->quoteSimpleTableName($name);
if ($schema !== '') {
$name = $schema . '.' . $name;
}
$tableMetadata = $this->getTableTypeMetadata($type, $name, $refresh);
if ($tableMetadata !== null) {
$metadata[] = $tableMetadata;
}
}
return $metadata;
}
| public getSchemaNames( boolean $refresh = false ): array | ||
| $refresh | boolean | |
public function getSchemaNames(bool $refresh = false): array
{
if (empty($this->schemaNames) || $refresh) {
$this->schemaNames = $this->findSchemaNames();
}
return $this->schemaNames;
}
| public getSchemaPrimaryKeys( string $schema = '', boolean $refresh = false ): array | ||
| $schema | string | |
| $refresh | boolean | |
public function getSchemaPrimaryKeys(string $schema = '', bool $refresh = false): array
{
/** @var Index[] */
return $this->getSchemaMetadata($schema, SchemaInterface::PRIMARY_KEY, $refresh);
}
| public getSchemaUniques( string $schema = '', boolean $refresh = false ): array | ||
| $schema | string | |
| $refresh | boolean | |
public function getSchemaUniques(string $schema = '', bool $refresh = false): array
{
/** @var Index[] */
return $this->getSchemaMetadata($schema, SchemaInterface::UNIQUES, $refresh);
}
| public getTableChecks( string $name, boolean $refresh = false ): array | ||
| $name | string | |
| $refresh | boolean | |
public function getTableChecks(string $name, bool $refresh = false): array
{
/** @var Check[] */
return $this->getTableMetadata($this->clearFullName($name), SchemaInterface::CHECKS, $refresh);
}
| public getTableDefaultValues( string $name, boolean $refresh = false ): array | ||
| $name | string | |
| $refresh | boolean | |
public function getTableDefaultValues(string $name, bool $refresh = false): array
{
/** @var DefaultValue[] */
return $this->getTableMetadata($this->clearFullName($name), SchemaInterface::DEFAULT_VALUES, $refresh);
}
| public getTableForeignKeys( string $name, boolean $refresh = false ): array | ||
| $name | string | |
| $refresh | boolean | |
public function getTableForeignKeys(string $name, bool $refresh = false): array
{
/** @var ForeignKey[] */
return $this->getTableMetadata($this->clearFullName($name), SchemaInterface::FOREIGN_KEYS, $refresh);
}
| public getTableIndexes( string $name, boolean $refresh = false ): array | ||
| $name | string | |
| $refresh | boolean | |
public function getTableIndexes(string $name, bool $refresh = false): array
{
/** @var Index[] */
return $this->getTableMetadata($this->clearFullName($name), SchemaInterface::INDEXES, $refresh);
}
Defined in: Yiisoft\Db\Schema\AbstractSchema::getTableMetadata()
Returns the metadata of the given type for the given table.
| protected getTableMetadata( string $name, string $type, boolean $refresh = false ): Yiisoft\Db\Constraint\Check[]|Yiisoft\Db\Constraint\DefaultValue[]|Yiisoft\Db\Constraint\ForeignKey[]|Yiisoft\Db\Constraint\Index|Yiisoft\Db\Constraint\Index[]|Yiisoft\Db\Schema\TableSchemaInterface|null | ||
| $name | string |
The table name. The table name may contain a schema name if any. Don't quote the table name. |
| $type | string |
The metadata type. |
| $refresh | boolean |
Whether to reload the table metadata even if it's found in the cache. |
| return | Yiisoft\Db\Constraint\Check[]|Yiisoft\Db\Constraint\DefaultValue[]|Yiisoft\Db\Constraint\ForeignKey[]|Yiisoft\Db\Constraint\Index|Yiisoft\Db\Constraint\Index[]|Yiisoft\Db\Schema\TableSchemaInterface|null |
The metadata of the given type for the given table. |
|---|---|---|
protected function getTableMetadata(
string $name,
string $type,
bool $refresh = false,
): array|Index|TableSchemaInterface|null {
if (!isset($this->tableMetadata[$name])) {
$this->loadTableMetadataFromCache($name);
}
if ($refresh || !isset($this->tableMetadata[$name][$type])) {
$this->tableMetadata[$name][$type] = $this->loadTableTypeMetadata($type, $name);
$this->saveTableMetadataToCache($name);
}
return $this->tableMetadata[$name][$type];
}
| public getTableNames( string $schema = '', boolean $refresh = false ): array | ||
| $schema | string | |
| $refresh | boolean | |
public function getTableNames(string $schema = '', bool $refresh = false): array
{
if (!isset($this->tableNames[$schema]) || $refresh) {
$this->tableNames[$schema] = $this->findTableNames($schema);
}
return $this->tableNames[$schema];
}
| public getTablePrimaryKey( string $name, boolean $refresh = false ): Yiisoft\Db\Constraint\Index|null | ||
| $name | string | |
| $refresh | boolean | |
public function getTablePrimaryKey(string $name, bool $refresh = false): ?Index
{
foreach ($this->getTableIndexes($name, $refresh) as $index) {
if ($index->isPrimaryKey) {
return $index;
}
}
return null;
}
| public getTableSchema( string $name, boolean $refresh = false ): Yiisoft\Db\Schema\TableSchemaInterface|null | ||
| $name | string | |
| $refresh | boolean | |
public function getTableSchema(string $name, bool $refresh = false): ?TableSchemaInterface
{
$rawName = $this->clearFullName($name);
if ($refresh) {
// Some constraints are loading and caching together.
// Reset the table constraint cache to load them without refreshing.
$this->tableMetadata[$rawName] = [];
if ($this->schemaCache->isEnabled()) {
$this->schemaCache->remove($this->getCacheKey($rawName));
}
}
/** @var TableSchemaInterface|null */
return $this->getTableMetadata($rawName, SchemaInterface::SCHEMA, $refresh);
}
| public getTableSchemas( string $schema = '', boolean $refresh = false ): array | ||
| $schema | string | |
| $refresh | boolean | |
public function getTableSchemas(string $schema = '', bool $refresh = false): array
{
/** @var TableSchemaInterface[] */
return $this->getSchemaMetadata($schema, SchemaInterface::SCHEMA, $refresh);
}
Defined in: Yiisoft\Db\Schema\AbstractSchema::getTableTypeMetadata()
This method returns the desired metadata type for table name (with refresh if needed).
| protected getTableTypeMetadata( string $type, string $name, boolean $refresh = false ): Yiisoft\Db\Constraint\Check[]|Yiisoft\Db\Constraint\DefaultValue[]|Yiisoft\Db\Constraint\ForeignKey[]|Yiisoft\Db\Constraint\Index|Yiisoft\Db\Constraint\Index[]|Yiisoft\Db\Schema\TableSchemaInterface|null | ||
| $type | string | |
| $name | string | |
| $refresh | boolean | |
protected function getTableTypeMetadata(
string $type,
string $name,
bool $refresh = false,
): array|Index|TableSchemaInterface|null {
return match ($type) {
SchemaInterface::SCHEMA => $this->getTableSchema($name, $refresh),
SchemaInterface::PRIMARY_KEY => $this->getTablePrimaryKey($name, $refresh),
SchemaInterface::UNIQUES => $this->getTableUniques($name, $refresh),
SchemaInterface::FOREIGN_KEYS => $this->getTableForeignKeys($name, $refresh),
SchemaInterface::INDEXES => $this->getTableIndexes($name, $refresh),
SchemaInterface::DEFAULT_VALUES => $this->getTableDefaultValues($name, $refresh),
SchemaInterface::CHECKS => $this->getTableChecks($name, $refresh),
default => null,
};
}
| public getTableUniques( string $name, boolean $refresh = false ): array | ||
| $name | string | |
| $refresh | boolean | |
public function getTableUniques(string $name, bool $refresh = false): array
{
return array_filter(
$this->getTableIndexes($name, $refresh),
static fn(Index $index): bool => $index->isUnique,
);
}
Defined in: Yiisoft\Db\Schema\AbstractSchema::getViewNames()
| public getViewNames( string $schema = '', boolean $refresh = false ): array | ||
| $schema | string | |
| $refresh | boolean | |
public function getViewNames(string $schema = '', bool $refresh = false): array
{
if (!isset($this->viewNames[$schema]) || $refresh) {
$this->viewNames[$schema] = $this->findViewNames($schema);
}
return $this->viewNames[$schema];
}
Defined in: Yiisoft\Db\Schema\AbstractSchema::hasSchema()
| public hasSchema( string $schema, boolean $refresh = false ): boolean | ||
| $schema | string | |
| $refresh | boolean | |
public function hasSchema(string $schema, bool $refresh = false): bool
{
$schemas = $this->getSchemaNames($refresh);
return in_array($schema, $schemas);
}
Defined in: Yiisoft\Db\Schema\AbstractSchema::hasTable()
| public hasTable( string $tableName, string $schema = '', boolean $refresh = false ): boolean | ||
| $tableName | string | |
| $schema | string | |
| $refresh | boolean | |
public function hasTable(string $tableName, string $schema = '', bool $refresh = false): bool
{
$tables = $this->getTableNames($schema, $refresh);
$rawTableName = $this->db->getQuoter()->getRawTableName($tableName);
return in_array($rawTableName, $tables);
}
Defined in: Yiisoft\Db\Schema\AbstractSchema::hasView()
| public hasView( string $viewName, string $schema = '', boolean $refresh = false ): boolean | ||
| $viewName | string | |
| $schema | string | |
| $refresh | boolean | |
public function hasView(string $viewName, string $schema = '', bool $refresh = false): bool
{
$views = $this->getViewNames($schema, $refresh);
$rawViewName = $this->db->getQuoter()->getRawTableName($viewName);
return in_array($rawViewName, $views);
}
Defined in: Yiisoft\Db\Schema\AbstractSchema::loadResultColumn()
Creates a new column instance according to the column metadata received from the query result.
| protected abstract loadResultColumn( array $metadata ): Yiisoft\Db\Schema\Column\ColumnInterface|null | ||
| $metadata | array |
The column metadata from the query result. |
abstract protected function loadResultColumn(array $metadata): ?ColumnInterface;
Defined in: Yiisoft\Db\Schema\AbstractSchema::loadTableChecks()
Loads all check constraints for the given table.
| protected abstract loadTableChecks( string $tableName ): Yiisoft\Db\Constraint\Check[] | ||
| $tableName | string |
The table name. |
| return | Yiisoft\Db\Constraint\Check[] |
The check constraints for the given table. |
|---|---|---|
abstract protected function loadTableChecks(string $tableName): array;
Defined in: Yiisoft\Db\Schema\AbstractSchema::loadTableDefaultValues()
Loads all default value constraints for the given table.
| protected abstract loadTableDefaultValues( string $tableName ): Yiisoft\Db\Constraint\DefaultValue[] | ||
| $tableName | string |
The table name. |
| return | Yiisoft\Db\Constraint\DefaultValue[] |
The default value constraints for the given table. |
|---|---|---|
abstract protected function loadTableDefaultValues(string $tableName): array;
Defined in: Yiisoft\Db\Schema\AbstractSchema::loadTableForeignKeys()
Loads all foreign keys for the given table.
| protected abstract loadTableForeignKeys( string $tableName ): Yiisoft\Db\Constraint\ForeignKey[] | ||
| $tableName | string |
The table name. |
| return | Yiisoft\Db\Constraint\ForeignKey[] |
The foreign keys for the given table, indexed by constraint name. |
|---|---|---|
abstract protected function loadTableForeignKeys(string $tableName): array;
Defined in: Yiisoft\Db\Schema\AbstractSchema::loadTableIndexes()
Loads all indexes for the given table.
| protected abstract loadTableIndexes( string $tableName ): Yiisoft\Db\Constraint\Index[] | ||
| $tableName | string |
The table name. |
| return | Yiisoft\Db\Constraint\Index[] |
The indexes for the given table. |
|---|---|---|
abstract protected function loadTableIndexes(string $tableName): array;
Defined in: Yiisoft\Db\Schema\AbstractSchema::loadTableSchema()
Loads the metadata for the specified table.
| protected abstract loadTableSchema( string $name ): Yiisoft\Db\Schema\TableSchemaInterface|null | ||
| $name | string |
The table name. |
| return | Yiisoft\Db\Schema\TableSchemaInterface|null |
DBMS-dependent table metadata, |
|---|---|---|
abstract protected function loadTableSchema(string $name): ?TableSchemaInterface;
Defined in: Yiisoft\Db\Schema\AbstractSchema::loadTableTypeMetadata()
This method returns the desired metadata type for the table name.
| protected loadTableTypeMetadata( string $type, string $name ): Yiisoft\Db\Constraint\Check[]|Yiisoft\Db\Constraint\DefaultValue[]|Yiisoft\Db\Constraint\ForeignKey[]|Yiisoft\Db\Constraint\Index[]|Yiisoft\Db\Schema\TableSchemaInterface|null | ||
| $type | string | |
| $name | string | |
protected function loadTableTypeMetadata(string $type, string $name): array|TableSchemaInterface|null
{
return match ($type) {
SchemaInterface::SCHEMA => $this->loadTableSchema($name),
SchemaInterface::FOREIGN_KEYS => $this->loadTableForeignKeys($name),
SchemaInterface::INDEXES => $this->loadTableIndexes($name),
SchemaInterface::DEFAULT_VALUES => $this->loadTableDefaultValues($name),
SchemaInterface::CHECKS => $this->loadTableChecks($name),
default => null,
};
}
Defined in: Yiisoft\Db\Schema\AbstractSchema::refresh()
| public refresh( ): void |
public function refresh(): void
{
if ($this->schemaCache->isEnabled()) {
$this->schemaCache->invalidate($this->getCacheTag());
}
$this->tableNames = [];
$this->tableMetadata = [];
$this->schemaNames = [];
$this->viewNames = [];
$this->resultColumns = [];
}
| public refreshTableSchema( string $name ): void | ||
| $name | string | |
public function refreshTableSchema(string $name): void
{
$rawName = $this->clearFullName($name);
unset($this->tableMetadata[$rawName]);
$this->tableNames = [];
$this->viewNames = [];
if ($this->schemaCache->isEnabled()) {
$this->schemaCache->remove($this->getCacheKey($rawName));
}
}
Defined in: Yiisoft\Db\Schema\AbstractSchema::resolveFullName()
Resolves the full table name, considering the default schema name. Removes curly brackets from the names, and replaces the percentage character '%' with Yiisoft\Db\Connection\ConnectionInterface::getTablePrefix().
| protected resolveFullName( string $name, string $schemaName = '' ): string | ||
| $name | string | |
| $schemaName | string | |
protected function resolveFullName(string $name, string $schemaName = ''): string
{
$quoter = $this->db->getQuoter();
$rawName = $quoter->getRawTableName($name);
return match ($schemaName) {
'', $this->defaultSchema => $rawName,
default => $quoter->getRawTableName($schemaName) . ".$rawName",
};
}
Defined in: Yiisoft\Db\Schema\AbstractSchema::setTableMetadata()
Sets the metadata of the given type for the given table.
| protected setTableMetadata( string $rawName, string $type, Yiisoft\Db\Constraint\Check[]|Yiisoft\Db\Constraint\DefaultValue[]|Yiisoft\Db\Constraint\ForeignKey[]|Yiisoft\Db\Constraint\Index|Yiisoft\Db\Constraint\Index[]|Yiisoft\Db\Schema\TableSchemaInterface|null $data ): void | ||
| $rawName | string |
The raw table name. |
| $type | string |
The metadata type. |
| $data | Yiisoft\Db\Constraint\Check[]|Yiisoft\Db\Constraint\DefaultValue[]|Yiisoft\Db\Constraint\ForeignKey[]|Yiisoft\Db\Constraint\Index|Yiisoft\Db\Constraint\Index[]|Yiisoft\Db\Schema\TableSchemaInterface|null |
The metadata to set. |
protected function setTableMetadata(
string $rawName,
string $type,
array|Index|TableSchemaInterface|null $data,
): void {
$this->tableMetadata[$rawName][$type] = $data;
}
Signup or Login in order to comment.