Schema control and metadata.
The column definition constants are two bytes each, used in bitwise composition.
<I_CONST>
) is used for the specific primary index type.<T_CONST>
) is used for the specific storage type.0x01
flags NOT NULL
Definition constants are never returned by this class' methods. The methods can only receive them.
Public Properties | |
const | DATETIME_FORMAT = 'Y-m-d H:i:s' |
const | I_PRIMARY = 0xfe00 |
<I_CONST> : One or more columns compose the primary key. More... | |
const | T_AUTOINCREMENT = self::I_AUTOINCREMENT | self::T_INT |
<T_CONST> : Column is the primary key and auto-increments (8-byte signed integer). More... | |
const | T_BLOB = 0x03 |
<T_CONST> : Arbitrary binary data up to 4GiB. More... | |
const | T_BLOB_NULL = 0x02 |
const | T_BOOL = 0xff |
<T_CONST> : Boolean analog (numeric). More... | |
const | T_BOOL_NULL = 0xfe |
const | T_CONST_NAMES |
Maps storage types to T_CONST names. More... | |
const | T_DATETIME = 0xf9 |
<T_CONST> : Native DATETIME type, stored as YYYY-MM-DD hh:mm:ss UTC. More... | |
const | T_DATETIME_NULL = 0xf8 |
const | T_FLOAT = 0xfb |
<T_CONST> : 8-byte IEEE floating point number. More... | |
const | T_FLOAT_NULL = 0xfa |
const | T_INT = 0xfd |
<T_CONST> : 8-byte signed integer. More... | |
const | T_INT_NULL = 0xfc |
const | T_STRING = 0xf7 |
<T_CONST> : UTF-8 up to 255 bytes. More... | |
const | T_STRING_NULL = 0xf6 |
const | T_TEXT = 0x05 |
<T_CONST> : UTF-8 up to 64KiB. More... | |
const | T_TEXT_NULL = 0x04 |
Protected Properties | |
int[] | $colDefs |
DB | $db |
Table[] | $tables = [] |
const | COLUMN_DEFINITIONS |
Driver-specific schema phrases. More... | |
const | I_AUTOINCREMENT = self::I_PRIMARY | 0x0100 |
Partial definition for T_AUTOINCREMENT , use that instead. More... | |
const | I_MASK = 0xff00 |
Higher byte mask (column index type). More... | |
const | PHP_TYPES |
Maps column types reported by the database into PHP native/annotated types. More... | |
const | T_MASK = 0xff |
Lower-byte mask (column storage type). More... | |
const | T_STRICT = 0x01 |
Flags whether a type is NOT NULL More... | |
Public Static Methods | |
magic static self | factory (DB $db) |
Public Methods | |
__construct (DB $db) | |
$this | addColumn (string $table, string $column, int $type=self::T_STRING_NULL) |
ALTER TABLE $table ADD COLUMN $column ... if it doesn't exist. More... | |
$this | addUniqueKey (string $table, array $columns) |
Driver-appropriate constraint creation. More... | |
$this | createTable (string $table, array $columns, array $foreign=[]) |
CREATE TABLE $table ... More... | |
$this | dropTable (string $table) |
DROP TABLE IF EXISTS $table More... | |
$this | dropUniqueKey (string $table, array $columns) |
Driver-appropriate constraint deletion. More... | |
array[] | getColumnInfo (string $table) |
Returns column metadata in an associative array. More... | |
DB | getDb () |
string | getForeignKeyName (string $table, string $column) |
FK_TABLE__COLUMN More... | |
string | getPrimaryKeyName (string $table, array $columns) |
PK_TABLE__COLUMN__COLUMN__COLUMN More... | |
null Table | getTable (string $name) |
string | getUniqueKeyName (string $table, array $columns) |
UQ_TABLE__COLUMN__COLUMN__COLUMN More... | |
bool | hasColumn (string $table, string $column) |
bool | hasUniqueKey (string $table, array $columns) |
bool | offsetExists ($table) |
Whether a table exists. More... | |
null Table | offsetGet ($table) |
Returns a table by name. More... | |
offsetSet ($offset, $value) | |
offsetUnset ($offset) | |
$this | renameTable (string $oldName, string $newName) |
ALTER TABLE $oldName RENAME TO $newName More... | |
Protected Methods | |
int[] | sortColumns (array $types) |
Sorts according to index priority, storage size/complexity, and name. More... | |
|
protected |
Driver-specific schema phrases.
|
protected |
Partial definition for T_AUTOINCREMENT
, use that instead.
|
protected |
Higher byte mask (column index type).
const I_PRIMARY = 0xfe00 |
<I_CONST>
: One or more columns compose the primary key.
|
protected |
Maps column types reported by the database into PHP native/annotated types.
This is used by Schema::getColumnInfo()
const T_AUTOINCREMENT = self::I_AUTOINCREMENT | self::T_INT |
<T_CONST>
: Column is the primary key and auto-increments (8-byte signed integer).
const T_BLOB = 0x03 |
<T_CONST>
: Arbitrary binary data up to 4GiB.
const T_BOOL = 0xff |
<T_CONST>
: Boolean analog (numeric).
const T_CONST_NAMES |
Maps storage types to T_CONST
names.
Resolved storage types in Record are keys here.
This is also used when generating migrations on the command-line.
const T_DATETIME = 0xf9 |
<T_CONST>
: Native DATETIME
type, stored as YYYY-MM-DD hh:mm:ss
UTC.
const T_FLOAT = 0xfb |
<T_CONST>
: 8-byte IEEE floating point number.
const T_INT = 0xfd |
<T_CONST>
: 8-byte signed integer.
|
protected |
Lower-byte mask (column storage type).
|
protected |
Flags whether a type is NOT NULL
const T_STRING = 0xf7 |
<T_CONST>
: UTF-8 up to 255 bytes.
const T_TEXT = 0x05 |
<T_CONST>
: UTF-8 up to 64KiB.
$this addColumn | ( | string | $table, |
string | $column, | ||
int | $type = self::T_STRING_NULL |
||
) |
ALTER TABLE $table ADD COLUMN $column ...
if it doesn't exist.
string | $table | |
string | $column | |
int | $type |
$this addUniqueKey | ( | string | $table, |
array | $columns | ||
) |
$this createTable | ( | string | $table, |
array | $columns, | ||
array | $foreign = [] |
||
) |
$this dropTable | ( | string | $table | ) |
$this dropUniqueKey | ( | string | $table, |
array | $columns | ||
) |
array [] getColumnInfo | ( | string | $table | ) |
Returns column metadata in an associative array.
Elements are:
name
type
: PHP native/annotated type (as a string)nullable
: booleanThe returned type
can be used to get a T_CONST
name from Schema::T_CONST_NAMES
string | $table | |
string | $column |
|
final |
FK_TABLE__COLUMN
string | $table | |
string | $column |
|
final |
PK_TABLE__COLUMN__COLUMN__COLUMN
string | $table | |
string[] | $columns |
null Table getTable | ( | string | $name | ) |
string | $name |
|
final |
UQ_TABLE__COLUMN__COLUMN__COLUMN
string | $table | |
string[] | $columns |
bool hasColumn | ( | string | $table, |
string | $column | ||
) |
string | $table | |
string | $column |
bool hasUniqueKey | ( | string | $table, |
array | $columns | ||
) |
string | $table | |
string[] | $columns |
|
final |
Whether a table exists.
string | $table |
null Table offsetGet | ( | $table | ) |
Returns a table by name.
string | $table |
|
final |
$offset | |
$value |
LogicException |
|
final |
$offset |
LogicException |
$this renameTable | ( | string | $oldName, |
string | $newName | ||
) |
|
protected |
Sorts according to index priority, storage size/complexity, and name.
int[] | $types |