com\setasign\SetaFramework\Database\Manager
TableSchema Class TableSchema
File: /SetaFramework/src/Database/Manager/TableSchema.php
Class hierarchy
Implements
Summary
Methods
- __construct()
- __clone()
- addColumns()
- addIndex()
- addPrimaryKey()
- addUnique()
- alter()
- count()
- create()
- getAlterChanges()
- getAutoSync()
- getCollation()
- getColumn()
- getColumnAfter()
- getColumnNames()
- getColumns()
- getEngine()
- getIndexes()
- getIndexesOfColumn()
- getName()
- getSyncSql()
- getTableExist()
- hasColumn()
- hasIndex()
- manuallySync()
- process()
- removeAllIndexes()
- removeColumns()
- removeIndex()
- rename()
- renameColumn()
- renameColumnInIndexes()
- reorderColumns()
- resetSync()
- setAutoSync()
- setCollation()
- setDatabaseManager()
- setEngine()
Constants
INDEX
INDEX_FULLTEXT
only possible in mysql
INDEX_PRIMARY_KEY
INDEX_UNIQUE
Properties
$collation
$databaseManager
$engine
$lastSync
If null the table doesn't exist yet
$tableName
Methods
__construct()
Column\AbstractColumn[] $columns,
?string $collation = null,
?string $engine = null
Parameters
- $tableName : string
- $columns : Column\AbstractColumn[]
- $collation : ?string
- $engine : ?string
Exceptions
Throws \InvalidArgumentException
addColumns()
Adds a one or more columns to the table
Parameters
- $addColumns : Column\AbstractColumn|Column\AbstractColumn[]
- $before : ?string
Add the columns before another column. If null the columns will be added to the end.
Exceptions
Throws \InvalidArgumentException On duplicate columnName
addIndex()
?string $indexName = null,
string $type = TableSchema::INDEX,
bool $merge = true
Adds an index to the table
Parameters
- $columnNames : string|string[]
- $indexName : ?string
- $type : string
- $merge : bool
Merge with existing indexes with $indexName; If false existing indexes will be replaced
addPrimaryKey()
Adds a primary key
Helper method that call addIndex
Parameters
- $columnNames : string|string[]
- $merge : bool
If false existing indexes will be replaced
addUnique()
?string $indexName = null,
bool $merge = true
Adds a unique key
Helper method that call addIndex
Parameters
- $columnNames : string|string[]
- $indexName : ?string
- $merge : bool
If false existing indexes will be replaced
getColumns()
Returns all column objects of the table in an array with "key = string $columnName" and "value = AbstractColumn $column"
getIndexesOfColumn()
Returns all indexes of a single column
Parameters
- $columnName : string
Return Values
The format is equal to Column::getIndexes before inserting into a TableSchema.
getSyncSql()
Returns the sql query which would be performed on sync
Exceptions
Throws \BadMethodCallException if autoSync is enabled.
hasIndex()
Checks whether the table has an index with the name $indexName
Parameters
- $indexName : string
manuallySync()
Manually sync the tableSchema with the database. Only useable if autoSync is disabled!
Parameters
- $simulationMode : bool
If this is true no query will be triggered
Exceptions
Throws \BadMethodCallException if autoSync is enabled.
process()
Helper method to edit multiple columns
The autoSync will be disabled before the callback and will be activated after the callback.
Parameters
- $callback : callable
- $simulationMode : bool
If this is true no query will be triggered
removeAllIndexes()
Deletes all indexes.
Parameters
- $columnNames : null|string|string[]
Only delete indexes from certain columns. Null to delete all indexes.
removeIndex()
null|string|string[] $columnNames = null
Removes an index
If $columnNames is set only specific columns will be removed from the index
Parameters
- $indexName : string
- $columnNames : null|string|string[]
renameColumn()
Renames a column
Call AbstractColumn::rename if possible.
Parameters
- $oldColumnName : string
- $newColumnName : string
Exceptions
Throws \com\setasign\SetaFramework\Exception If oldColumnName is unknown or the newColumnName already exist
resetSync()
This method is only supposed for setup of tableSchema in AbstractManager::getTableSchema.
setAutoSync()
Enable/Disable autoSync
If autoSync was disable and it will be enabled, the sync method will be called.
Parameters
- $autoSync : bool
- $simulationMode : bool
If this is true no query will be triggered
setDatabaseManager()
Parameters
- $abstractManager : AbstractManager
- $autoSync : bool
- $tableExist : bool
If this is true the actual data will be handled as the actual state of the database.
