Skip to content

Schema ​

Type
Class
Namespace
craft\db\pgsql
Inherits
craft\db\pgsql\Schema » yii\db\pgsql\Schema » yii\db\Schema » yii\base\BaseObject
Implements
yii\base\Configurable, yii\db\ConstraintFinderInterface
Uses traits
yii\db\ConstraintFinderTrait, yii\db\ViewFinderTrait
Since
3.0.0

View source

Public Properties ​

PropertyDescription
backupFormatstring, null
columnSchemaClassstring, array – Column schema class or class config
dbcraft\db\Connection
defaultBackupCommandstring – The command to execute
defaultRestoreCommandstring – The command to execute
defaultSchemastring – The default schema used for the current session.
exceptionMaparray – Map of DB errors and corresponding exceptions If left part is found in DB error message exception class from the right part is used.
lastInsertIDstring – The row ID of the last row inserted, or the last value retrieved from the sequence object.
maxObjectNameLengthinteger – The maximum length that objects' names can be.
queryBuilderyii\db\QueryBuilder – The query builder for this connection.
restoreFormatstring, null
schemaChecks\yii\db\CheckConstraint[][] – Check constraints for all tables in the database.
schemaDefaultValuesyii\db\DefaultValueConstraint – Default value constraints for all tables in the database.
schemaForeignKeys\yii\db\ForeignKeyConstraint[][] – Foreign keys for all tables in the database.
schemaIndexes\yii\db\IndexConstraint[][] – Indexes for all tables in the database.
schemaNamesstring[] – All schema names in the database, except system schemas.
schemaPrimaryKeysyii\db\Constraint – Primary keys for all tables in the database.
schemaUniques\yii\db\IndexConstraint[][] – Unique constraints for all tables in the database.
serverVersionstring – Server version as a string.
tableNamesstring[] – All table names in the database.
tableSchemasyii\db\TableSchema – The metadata for all tables in the database.
transactionIsolationLevelstring – The transaction isolation level to use for this transaction.
typeMaparray – Mapping from physical column types (keys) to abstract column types (values)
viewNamesstring[] – All view names in the database.

backupFormat ​

Type
string, null
Default value
null
Since
5.2.0

View source

db ​

Type
craft\db\Connection
Default value
null

View source

defaultBackupCommand ​

Type
string
Default value
null
Access
Read-only

The command to execute

View source

defaultRestoreCommand ​

Type
string
Default value
null
Access
Read-only

The command to execute

View source

maxObjectNameLength ​

Type
integer
Default value
63

The maximum length that objects' names can be.

View source

restoreFormat ​

Type
string, null
Default value
null
Since
5.2.0

View source

Protected Properties ​

PropertyDescription
columnQuoteCharacterstring, string[] – Character used to quote column names.
tableQuoteCharacterstring, string[] – Character used to quote schema, table, etc.

Public Methods ​

MethodDescription
__call()Calls the named method which is not a class method.
__construct()Constructor.
__get()Returns the value of an object property.
__isset()Checks if a property is set, i.e. defined and not null.
__set()Sets value of an object property.
__unset()Sets an object property to null.
canGetProperty()Returns a value indicating whether a property can be read.
canSetProperty()Returns a value indicating whether a property can be set.
className()Returns the fully qualified name of this class.
convertException()Converts a DB exception to a more concrete one if possible.
createColumnSchemaBuilder()Create a column schema builder instance giving the type and value precision.
createQueryBuilder()Creates a query builder for the database.
createSavepoint()Creates a new savepoint.
findIndexes()Returns all indexes for the given table. Each array element is of the following structure:
findUniqueIndexes()Returns all unique indexes for the given table.
getBackupFormat()Returns the backup format that should be used (custom, directory, tar, or plain).
getDefaultBackupCommand()Returns the default backup command to execute.
getDefaultRestoreCommand()Returns the default database restore command to execute.
getLastInsertID()Returns the ID of the last inserted row or sequence value.
getPdoType()Determines the PDO type for the given PHP data value.
getQueryBuilder()
getRawTableName()Returns the actual name of a given table name.
getRestoreFormat()Returns the restore format that should be used (custom, directory, tar, or plain).
getSchemaChecks()Returns check constraints for all tables in the database.
getSchemaDefaultValues()Returns default value constraints for all tables in the database.
getSchemaForeignKeys()Returns foreign keys for all tables in the database.
getSchemaIndexes()Returns indexes for all tables in the database.
getSchemaNames()Returns all schema names in the database, except system schemas.
getSchemaPrimaryKeys()Returns primary keys for all tables in the database.
getSchemaUniques()Returns unique constraints for all tables in the database.
getServerVersion()Returns a server version as a string comparable by \version_compare().
getTableChecks()Obtains the check constraints information for the named table.
getTableDefaultValues()Obtains the default value constraints information for the named table.
getTableForeignKeys()Obtains the foreign keys information for the named table.
getTableIndexes()Obtains the indexes information for the named table.
getTableNames()Returns all table names in the database.
getTablePrimaryKey()Obtains the primary key for the named table.
getTableSchema()Obtains the schema information for the named table.
getTableSchemas()Returns the metadata for all tables in the database.
getTableUniques()Obtains the unique constraints information for the named table.
getViewNames()Returns all view names in the database.
hasMethod()Returns a value indicating whether a method is defined.
hasProperty()Returns a value indicating whether a property is defined.
init()Initializes the object.
insert()Executes the INSERT command, returning primary key values.
isReadQuery()Returns a value indicating whether a SQL statement is for read purpose.
loadTableSchema()Loads the metadata for the specified table.
quoteColumnName()Quotes a column name for use in a query.
quoteDatabaseName()Quotes a database name for use in a query.
quoteSimpleColumnName()Quotes a simple column name for use in a query.
quoteSimpleTableName()Quotes a simple table name for use in a query.
quoteTableName()Quotes a table name for use in a query.
quoteValue()Quotes a string value for use in a query.
refresh()Refreshes the schema.
refreshTableSchema()Refreshes the particular table schema.
releaseSavepoint()Releases an existing savepoint.
rollBackSavepoint()Rolls back to a previously created savepoint.
setBackupFormat()Sets the backup format that should be used (custom, directory, tar, or plain).
setRestoreFormat()Sets the restore format that should be used (custom, directory, tar, or plain).
setTransactionIsolationLevel()Sets the isolation level of the current transaction.
supportsMb4()Returns whether a table supports 4-byte characters.
supportsSavepoint()
unquoteSimpleColumnName()Unquotes a simple column name.
unquoteSimpleTableName()Unquotes a simple table name.
usePgRestore()Whether pg_restore should be used for the restore command.

createQueryBuilder() ​

Creates a query builder for the database.

This method may be overridden by child classes to create a DBMS-specific query builder.

View source

Returns ​

craft\db\pgsql\QueryBuilder – Query builder instance

findIndexes() ​

Returns all indexes for the given table. Each array element is of the following structure:

php
[
    'IndexName' => [
        'columns' => ['col1' [, ...]],
        'unique' => false
    ],
]

View source

Arguments ​

  • $tableName (string) – The name of the table to get the indexes for.

Returns ​

array – All indexes for the given table.

getBackupFormat() ​

Since
5.2.0

Returns the backup format that should be used (custom, directory, tar, or plain).

View source

Returns ​

string, null

getDefaultBackupCommand() ​

Returns the default backup command to execute.

View source

Arguments ​

  • $ignoreTables (string[], null) – The table names whose data should be excluded from the backup

Returns ​

string – The command to execute

getDefaultRestoreCommand() ​

Returns the default database restore command to execute.

View source

Returns ​

string – The command to execute

getLastInsertID() ​

Returns the ID of the last inserted row or sequence value.

View source

Arguments ​

  • $sequenceName (string) – Name of the sequence object (required by some DBMS)

Returns ​

string – The row ID of the last row inserted, or the last value retrieved from the sequence object

Throws ​

getRestoreFormat() ​

Since
5.2.0

Returns the restore format that should be used (custom, directory, tar, or plain).

View source

Returns ​

string, null

getTableSchema() ​

Obtains the schema information for the named table.

View source

Arguments ​

  • $name
  • $refresh

Returns ​

craft\db\TableSchema, null –

loadTableSchema() ​

Loads the metadata for the specified table.

View source

Arguments ​

  • $name (string) – Table name

Returns ​

craft\db\TableSchema, null – Driver dependent table metadata. Null if the table does not exist.

quoteDatabaseName() ​

DEPRECATED

Deprecated in 5.4.0

Quotes a database name for use in a query.

View source

Arguments ​

Returns ​

string

releaseSavepoint() ​

Releases an existing savepoint.

View source

Arguments ​

  • $name (string) – The savepoint name.

Throws ​

rollBackSavepoint() ​

Rolls back to a previously created savepoint.

View source

Arguments ​

  • $name (string) – The savepoint name.

Throws ​

setBackupFormat() ​

Since
5.2.0

Sets the backup format that should be used (custom, directory, tar, or plain).

View source

Arguments ​

setRestoreFormat() ​

Since
5.2.0

Sets the restore format that should be used (custom, directory, tar, or plain).

View source

Arguments ​

supportsMb4() ​

Since
5.0.0

Returns whether a table supports 4-byte characters.

View source

Arguments ​

  • $table (string) – The table to check

Returns ​

boolean

usePgRestore() ​

Since
5.1.0

Whether pg_restore should be used for the restore command.

View source

Returns ​

boolean

Protected Methods ​

MethodDescription
createColumnSchema()Creates a column schema for the database.
findColumns()Collects the metadata of table columns.
findConstraints()Collects extra foreign key information details for the given table.
findSchemaNames()Returns all schema names in the database, including the default one but not system schemas.
findTableNames()Returns all table names in the database.
findViewNames(){@inheritdoc]
getCacheKey()Returns the cache key for the specified table name.
getCacheTag()Returns the cache tag name.
getColumnPhpType()Extracts the PHP type from abstract DB type.
getIndexInformation()Gets information about given table indexes.
getSchemaMetadata()Returns the metadata of the given type for all tables in the given schema.
getTableMetadata()Returns the metadata of the given type for the given table.
getTableNameParts()Splits full table name into parts
getUniqueIndexInformation()Gets information about given table unique indexes.
loadColumnSchema()Loads the column information into a yii\db\pgsql\ColumnSchema object.
loadTableChecks()
loadTableDefaultValues()
loadTableForeignKeys()
loadTableIndexes()
loadTablePrimaryKey()
loadTableUniques()
normalizePdoRowKeyCase()Changes row's array key case to lower if PDO's one is set to uppercase.
resolveTableName()Resolves the table name and schema name (if any).
resolveTableNames()Resolves the table name and schema name (if any).
setTableMetadata()Sets the metadata of the given type for the given table.

findConstraints() ​

Collects extra foreign key information details for the given table.

View source

Arguments ​

getIndexInformation() ​

Gets information about given table indexes.

View source

Arguments ​

Returns ​

array – Index and column names

Constants ​

ConstantDescription
SCHEMA_CACHE_VERSIONSchema cache version, to detect incompatibilities in cached values when the data format of the cache changes.
TYPE_BIGINT
TYPE_BIGPK
TYPE_BINARY
TYPE_BOOLEAN
TYPE_CHAR
TYPE_DATE
TYPE_DATETIME
TYPE_DECIMAL
TYPE_DOUBLE
TYPE_FLOAT
TYPE_INTEGER
TYPE_JSON
TYPE_JSONB
TYPE_MONEY
TYPE_PK
TYPE_SMALLINT
TYPE_STRING
TYPE_TEXT
TYPE_TIME
TYPE_TIMESTAMP
TYPE_TINYINT
TYPE_UBIGPK
TYPE_UPK