AbstractStructure
extends AbstractTable
in package
Schema abstract design table class for CREATE and ALTER
Tags
Table of Contents
Constants
- BACKTICK = 'BACKTICK'
- Constants for id quote types
- BRACKET = 'BRACKET'
- DOUBLE_QUOTE = 'DOUBLE_QUOTE'
- MYSQL = 'MYSQL'
- Constants for database types
- NO_QUOTE = 'NO_QUOTE'
- PGSQL = 'PGSQL'
- SQLITE = 'SQLITE'
- SQLSRV = 'SQLSRV'
Properties
- $aggregateFunctions : array<string|int, mixed>
- Supported standard SQL aggregate functions
- $closeQuote : string|null
- ID close quote
- $columns : array<string|int, mixed>
- Columns to be added or modified
- $constraints : array<string|int, mixed>
- Constraints to be added
- $currentColumn : string|null
- Current column
- $currentConstraint : string|null
- Current constraint
- $dateTimeFunctions : array<string|int, mixed>
- Supported standard SQL date-time functions
- $db : AbstractAdapter|null
- Database object
- $dbType : string|null
- Database type
- $idQuoteType : string
- ID quote type
- $indices : array<string|int, mixed>
- Indices to be created
- $info : array<string|int, mixed>
- Table info
- $mathFunctions : array<string|int, mixed>
- Supported standard SQL math functions
- $openQuote : string|null
- ID open quote
- $parameterCount : int
- Parameter count
- $placeholder : string|null
- SQL placeholder
- $stringFunctions : array<string|int, mixed>
- Supported standard SQL string functions
- $table : string|null
- Table name
Methods
- __construct() : mixed
- Constructor
- __toString() : string
- Render the table schema to string
- addColumn() : AbstractStructure
- Add a column
- addColumnAttribute() : AbstractStructure
- Add a custom column attribute
- bigInt() : AbstractStructure
- Add a BIGINT column
- blob() : AbstractStructure
- Add a BLOB column
- char() : AbstractStructure
- Add a CHAR column
- column() : AbstractStructure
- Set the current column
- constraint() : AbstractStructure
- Set the current constraint
- date() : AbstractStructure
- Add a DATE column
- datetime() : AbstractStructure
- Add a DATETIME column
- db() : AbstractAdapter|null
- Get the current database adapter object (alias method)
- decimal() : AbstractStructure
- Add a DECIMAL column
- decrementParameterCount() : AbstractSql
- Decrement parameter count
- defaultIs() : AbstractStructure
- Set the current column's default value
- double() : AbstractStructure
- Add a DOUBLE column
- float() : AbstractStructure
- Add a FLOAT column
- foreignKey() : AbstractStructure
- Create a FOREIGN KEY constraint
- getCloseQuote() : string|null
- Get close quote
- getColumn() : string|null
- Get the current column
- getConstraint() : string|null
- Get the current constraint
- getDb() : AbstractAdapter|null
- Get the current database adapter object
- getDbType() : string|null
- Get the current database type
- getIdQuoteType() : string
- Get the quote ID type
- getIncrement() : array<string|int, mixed>
- Get the increment column(s)
- getInfo() : array<string|int, mixed>
- Get the table info
- getOpenQuote() : string|null
- Get open quote
- getParameter() : string
- Get parameter placeholder value
- getParameterCount() : int
- Get parameter count
- getPlaceholder() : string|null
- Get the SQL placeholder
- getPrimary() : array<string|int, mixed>
- Get the primary key column(s)
- getTable() : string
- Get the table name
- hasColumn() : bool
- Determine if the table has a column
- hasIncrement() : bool
- Determine if the table has an increment column
- hasPrimary() : bool
- Determine if the table has a primary key column
- increment() : AbstractStructure
- Set the current column as an increment column
- incrementParameterCount() : AbstractSql
- Increment parameter count
- index() : AbstractStructure
- Create an index
- int() : AbstractStructure
- Add an INT column
- integer() : AbstractStructure
- Add an INTEGER column
- isMysql() : bool
- Determine if the DB type is MySQL
- isParameter() : bool
- Check if value is parameter placeholder
- isPgsql() : bool
- Determine if the DB type is PostgreSQL
- isSqlite() : bool
- Determine if the DB type is SQLite
- isSqlsrv() : bool
- Determine if the DB type is SQL Server
- isSupportedFunction() : bool
- Check if value contains a standard SQL supported function
- longBlob() : AbstractStructure
- Add a LONGBLOB column
- longText() : AbstractStructure
- Add a LONGTEXT column
- mediumBlob() : AbstractStructure
- Add a MEDIUMBLOB column
- mediumInt() : AbstractStructure
- Add a MEDIUMINT column
- mediumText() : AbstractStructure
- Add a MEDIUMTEXT column
- notNullable() : AbstractStructure
- Set the current column as NOT nullable
- nullable() : AbstractStructure
- Set the current column as nullable
- numeric() : AbstractStructure
- Add a NUMERIC column
- on() : AbstractStructure
- Assign FOREIGN KEY reference table column
- onDelete() : AbstractStructure
- Assign FOREIGN KEY ON DELETE action
- primary() : AbstractStructure
- Create a PRIMARY KEY index
- quote() : float|int|string
- Quote the value (if it is not a numeric value)
- quoteId() : string
- Quote the identifier
- real() : AbstractStructure
- Add a REAL column
- references() : AbstractStructure
- Assign FOREIGN KEY reference table
- render() : string
- Render the table schema
- renderToStatements() : array<string|int, mixed>
- Render the table schema to an array of statements
- setIdQuoteType() : AbstractSql
- Set the quote ID type
- setPlaceholder() : AbstractSql
- Set the placeholder
- smallInt() : AbstractStructure
- Add a SMALLINT column
- text() : AbstractStructure
- Add a TEXT column
- time() : AbstractStructure
- Add a TIME column
- timestamp() : AbstractStructure
- Add a TIMESTAMP column
- tinyInt() : AbstractStructure
- Add a TINYINT column
- tinyText() : AbstractStructure
- Add a TINYTEXT column
- unique() : AbstractStructure
- Create a UNIQUE index
- unsigned() : AbstractStructure
- Set the current column as unsigned
- varchar() : AbstractStructure
- Add a VARCHAR column
- year() : AbstractStructure
- Add a YEAR column
- getColumnSchema() : string
- Format column schema
- init() : void
- Initialize SQL object
- initQuoteType() : void
- Initialize quite type
Constants
BACKTICK
Constants for id quote types
public
mixed
BACKTICK
= 'BACKTICK'
BRACKET
public
mixed
BRACKET
= 'BRACKET'
DOUBLE_QUOTE
public
mixed
DOUBLE_QUOTE
= 'DOUBLE_QUOTE'
MYSQL
Constants for database types
public
mixed
MYSQL
= 'MYSQL'
NO_QUOTE
public
mixed
NO_QUOTE
= 'NO_QUOTE'
PGSQL
public
mixed
PGSQL
= 'PGSQL'
SQLITE
public
mixed
SQLITE
= 'SQLITE'
SQLSRV
public
mixed
SQLSRV
= 'SQLSRV'
Properties
$aggregateFunctions
Supported standard SQL aggregate functions
protected
static array<string|int, mixed>
$aggregateFunctions
= ['AVG', 'COUNT', 'MAX', 'MIN', 'SUM']
$closeQuote
ID close quote
protected
string|null
$closeQuote
= null
$columns
Columns to be added or modified
protected
array<string|int, mixed>
$columns
= []
$constraints
Constraints to be added
protected
array<string|int, mixed>
$constraints
= []
$currentColumn
Current column
protected
string|null
$currentColumn
= null
$currentConstraint
Current constraint
protected
string|null
$currentConstraint
= null
$dateTimeFunctions
Supported standard SQL date-time functions
protected
static array<string|int, mixed>
$dateTimeFunctions
= ['CURRENT_DATE', 'CURRENT_TIMESTAMP', 'CURRENT_TIME', 'CURDATE', 'CURTIME', 'DATE', 'DATETIME', 'DAY', 'EXTRACT', 'GETDATE', 'HOUR', 'LOCALTIME', 'LOCALTIMESTAMP', 'MINUTE', 'MONTH', 'NOW', 'SECOND', 'TIME', 'TIMEDIFF', 'TIMESTAMP', 'UNIX_TIMESTAMP', 'YEAR']
$db
Database object
protected
AbstractAdapter|null
$db
= null
$dbType
Database type
protected
string|null
$dbType
= null
$idQuoteType
ID quote type
protected
string
$idQuoteType
= 'NO_QUOTE'
$indices
Indices to be created
protected
array<string|int, mixed>
$indices
= []
$info
Table info
protected
array<string|int, mixed>
$info
= []
$mathFunctions
Supported standard SQL math functions
protected
static array<string|int, mixed>
$mathFunctions
= ['ABS', 'RAND', 'SQRT', 'POW', 'POWER', 'EXP', 'LN', 'LOG', 'LOG10', 'GREATEST', 'LEAST', 'DIV', 'MOD', 'ROUND', 'TRUNC', 'CEIL', 'CEILING', 'FLOOR', 'COS', 'ACOS', 'ACOSH', 'SIN', 'SINH', 'ASIN', 'ASINH', 'TAN', 'TANH', 'ATANH', 'ATAN2']
$openQuote
ID open quote
protected
string|null
$openQuote
= null
$parameterCount
Parameter count
protected
int
$parameterCount
= 0
$placeholder
SQL placeholder
protected
string|null
$placeholder
= null
$stringFunctions
Supported standard SQL string functions
protected
static array<string|int, mixed>
$stringFunctions
= ['CONCAT', 'FORMAT', 'INSTR', 'LCASE', 'LEFT', 'LENGTH', 'LOCATE', 'LOWER', 'LPAD', 'LTRIM', 'POSITION', 'QUOTE', 'REGEXP', 'REPEAT', 'REPLACE', 'REVERSE', 'RIGHT', 'RPAD', 'RTRIM', 'SPACE', 'STRCMP', 'SUBSTRING', 'SUBSTR', 'TRIM', 'UCASE', 'UPPER']
$table
Table name
protected
string|null
$table
= null
Methods
__construct()
Constructor
public
__construct(AbstractAdapter $db) : mixed
Instantiate the SQL object
Parameters
- $db : AbstractAdapter
__toString()
Render the table schema to string
public
abstract __toString() : string
Return values
stringaddColumn()
Add a column
public
addColumn(string $name, string $type[, mixed $size = null ][, mixed $precision = null ][, array<string|int, mixed> $attributes = [] ]) : AbstractStructure
Parameters
- $name : string
- $type : string
- $size : mixed = null
- $precision : mixed = null
- $attributes : array<string|int, mixed> = []
Return values
AbstractStructureaddColumnAttribute()
Add a custom column attribute
public
addColumnAttribute(string $attribute) : AbstractStructure
Parameters
- $attribute : string
Return values
AbstractStructurebigInt()
Add a BIGINT column
public
bigInt(string $name[, mixed $size = null ][, array<string|int, mixed> $attributes = [] ]) : AbstractStructure
Parameters
- $name : string
- $size : mixed = null
- $attributes : array<string|int, mixed> = []
Return values
AbstractStructureblob()
Add a BLOB column
public
blob(string $name[, array<string|int, mixed> $attributes = [] ]) : AbstractStructure
Parameters
- $name : string
- $attributes : array<string|int, mixed> = []
Return values
AbstractStructurechar()
Add a CHAR column
public
char(string $name[, int $size = null ][, array<string|int, mixed> $attributes = [] ]) : AbstractStructure
Parameters
- $name : string
- $size : int = null
- $attributes : array<string|int, mixed> = []
Return values
AbstractStructurecolumn()
Set the current column
public
column(string $column) : AbstractStructure
Parameters
- $column : string
Return values
AbstractStructureconstraint()
Set the current constraint
public
constraint(string $constraint) : AbstractStructure
Parameters
- $constraint : string
Return values
AbstractStructuredate()
Add a DATE column
public
date(string $name[, array<string|int, mixed> $attributes = [] ]) : AbstractStructure
Parameters
- $name : string
- $attributes : array<string|int, mixed> = []
Return values
AbstractStructuredatetime()
Add a DATETIME column
public
datetime(string $name[, array<string|int, mixed> $attributes = [] ]) : AbstractStructure
Parameters
- $name : string
- $attributes : array<string|int, mixed> = []
Return values
AbstractStructuredb()
Get the current database adapter object (alias method)
public
db() : AbstractAdapter|null
Return values
AbstractAdapter|nulldecimal()
Add a DECIMAL column
public
decimal(string $name[, mixed $size = null ][, mixed $precision = null ][, array<string|int, mixed> $attributes = [] ]) : AbstractStructure
Parameters
- $name : string
- $size : mixed = null
- $precision : mixed = null
- $attributes : array<string|int, mixed> = []
Return values
AbstractStructuredecrementParameterCount()
Decrement parameter count
public
decrementParameterCount() : AbstractSql
Return values
AbstractSqldefaultIs()
Set the current column's default value
public
defaultIs(mixed $value) : AbstractStructure
Parameters
- $value : mixed
Return values
AbstractStructuredouble()
Add a DOUBLE column
public
double(string $name[, mixed $size = null ][, mixed $precision = null ][, array<string|int, mixed> $attributes = [] ]) : AbstractStructure
Parameters
- $name : string
- $size : mixed = null
- $precision : mixed = null
- $attributes : array<string|int, mixed> = []
Return values
AbstractStructurefloat()
Add a FLOAT column
public
float(string $name[, mixed $size = null ][, mixed $precision = null ][, array<string|int, mixed> $attributes = [] ]) : AbstractStructure
Parameters
- $name : string
- $size : mixed = null
- $precision : mixed = null
- $attributes : array<string|int, mixed> = []
Return values
AbstractStructureforeignKey()
Create a FOREIGN KEY constraint
public
foreignKey(string $column[, string|null $name = null ]) : AbstractStructure
Parameters
- $column : string
- $name : string|null = null
Return values
AbstractStructuregetCloseQuote()
Get close quote
public
getCloseQuote() : string|null
Return values
string|nullgetColumn()
Get the current column
public
getColumn() : string|null
Return values
string|nullgetConstraint()
Get the current constraint
public
getConstraint() : string|null
Return values
string|nullgetDb()
Get the current database adapter object
public
getDb() : AbstractAdapter|null
Return values
AbstractAdapter|nullgetDbType()
Get the current database type
public
getDbType() : string|null
Return values
string|nullgetIdQuoteType()
Get the quote ID type
public
getIdQuoteType() : string
Return values
stringgetIncrement()
Get the increment column(s)
public
getIncrement([bool $quote = false ]) : array<string|int, mixed>
Parameters
- $quote : bool = false
Return values
array<string|int, mixed>getInfo()
Get the table info
public
getInfo() : array<string|int, mixed>
Return values
array<string|int, mixed>getOpenQuote()
Get open quote
public
getOpenQuote() : string|null
Return values
string|nullgetParameter()
Get parameter placeholder value
public
getParameter(mixed $value[, string|null $column = null ]) : string
Parameters
- $value : mixed
- $column : string|null = null
Return values
stringgetParameterCount()
Get parameter count
public
getParameterCount() : int
Return values
intgetPlaceholder()
Get the SQL placeholder
public
getPlaceholder() : string|null
Return values
string|nullgetPrimary()
Get the primary key column(s)
public
getPrimary([bool $quote = false ]) : array<string|int, mixed>
Parameters
- $quote : bool = false
Return values
array<string|int, mixed>getTable()
Get the table name
public
getTable() : string
Return values
stringhasColumn()
Determine if the table has a column
public
hasColumn(string $name) : bool
Parameters
- $name : string
Return values
boolhasIncrement()
Determine if the table has an increment column
public
hasIncrement() : bool
Return values
boolhasPrimary()
Determine if the table has a primary key column
public
hasPrimary() : bool
Return values
boolincrement()
Set the current column as an increment column
public
increment([int $start = 1 ]) : AbstractStructure
Parameters
- $start : int = 1
Return values
AbstractStructureincrementParameterCount()
Increment parameter count
public
incrementParameterCount() : AbstractSql
Return values
AbstractSqlindex()
Create an index
public
index(string|array<string|int, mixed> $column[, string|null $name = null ][, string $type = 'index' ]) : AbstractStructure
Parameters
- $column : string|array<string|int, mixed>
- $name : string|null = null
- $type : string = 'index'
Return values
AbstractStructureint()
Add an INT column
public
int(string $name[, mixed $size = null ][, array<string|int, mixed> $attributes = [] ]) : AbstractStructure
Parameters
- $name : string
- $size : mixed = null
- $attributes : array<string|int, mixed> = []
Return values
AbstractStructureinteger()
Add an INTEGER column
public
integer(string $name[, mixed $size = null ][, array<string|int, mixed> $attributes = [] ]) : AbstractStructure
Parameters
- $name : string
- $size : mixed = null
- $attributes : array<string|int, mixed> = []
Return values
AbstractStructureisMysql()
Determine if the DB type is MySQL
public
isMysql() : bool
Return values
boolisParameter()
Check if value is parameter placeholder
public
isParameter(mixed $value[, string|null $column = null ]) : bool
Parameters
- $value : mixed
- $column : string|null = null
Return values
boolisPgsql()
Determine if the DB type is PostgreSQL
public
isPgsql() : bool
Return values
boolisSqlite()
Determine if the DB type is SQLite
public
isSqlite() : bool
Return values
boolisSqlsrv()
Determine if the DB type is SQL Server
public
isSqlsrv() : bool
Return values
boolisSupportedFunction()
Check if value contains a standard SQL supported function
public
static isSupportedFunction(string $value) : bool
Parameters
- $value : string
Return values
boollongBlob()
Add a LONGBLOB column
public
longBlob(string $name[, array<string|int, mixed> $attributes = [] ]) : AbstractStructure
Parameters
- $name : string
- $attributes : array<string|int, mixed> = []
Return values
AbstractStructurelongText()
Add a LONGTEXT column
public
longText(string $name[, array<string|int, mixed> $attributes = [] ]) : AbstractStructure
Parameters
- $name : string
- $attributes : array<string|int, mixed> = []
Return values
AbstractStructuremediumBlob()
Add a MEDIUMBLOB column
public
mediumBlob(string $name[, array<string|int, mixed> $attributes = [] ]) : AbstractStructure
Parameters
- $name : string
- $attributes : array<string|int, mixed> = []
Return values
AbstractStructuremediumInt()
Add a MEDIUMINT column
public
mediumInt(string $name[, mixed $size = null ][, array<string|int, mixed> $attributes = [] ]) : AbstractStructure
Parameters
- $name : string
- $size : mixed = null
- $attributes : array<string|int, mixed> = []
Return values
AbstractStructuremediumText()
Add a MEDIUMTEXT column
public
mediumText(string $name[, array<string|int, mixed> $attributes = [] ]) : AbstractStructure
Parameters
- $name : string
- $attributes : array<string|int, mixed> = []
Return values
AbstractStructurenotNullable()
Set the current column as NOT nullable
public
notNullable() : AbstractStructure
Return values
AbstractStructurenullable()
Set the current column as nullable
public
nullable() : AbstractStructure
Return values
AbstractStructurenumeric()
Add a NUMERIC column
public
numeric(string $name[, mixed $size = null ][, mixed $precision = null ][, array<string|int, mixed> $attributes = [] ]) : AbstractStructure
Parameters
- $name : string
- $size : mixed = null
- $precision : mixed = null
- $attributes : array<string|int, mixed> = []
Return values
AbstractStructureon()
Assign FOREIGN KEY reference table column
public
on(string $foreignColumn) : AbstractStructure
Parameters
- $foreignColumn : string
Return values
AbstractStructureonDelete()
Assign FOREIGN KEY ON DELETE action
public
onDelete([string|null $action = null ]) : AbstractStructure
Parameters
- $action : string|null = null
Return values
AbstractStructureprimary()
Create a PRIMARY KEY index
public
primary([string|array<string|int, mixed>|null $column = null ][, string|null $name = null ]) : AbstractStructure
Parameters
- $column : string|array<string|int, mixed>|null = null
- $name : string|null = null
Return values
AbstractStructurequote()
Quote the value (if it is not a numeric value)
public
quote([string|null $value = null ][, bool $force = false ]) : float|int|string
Parameters
- $value : string|null = null
- $force : bool = false
Return values
float|int|stringquoteId()
Quote the identifier
public
quoteId(string $identifier) : string
Parameters
- $identifier : string
Return values
stringreal()
Add a REAL column
public
real(string $name[, mixed $size = null ][, mixed $precision = null ][, array<string|int, mixed> $attributes = [] ]) : AbstractStructure
Parameters
- $name : string
- $size : mixed = null
- $precision : mixed = null
- $attributes : array<string|int, mixed> = []
Return values
AbstractStructurereferences()
Assign FOREIGN KEY reference table
public
references(string $foreignTable) : AbstractStructure
Parameters
- $foreignTable : string
Return values
AbstractStructurerender()
Render the table schema
public
abstract render() : string
Return values
stringrenderToStatements()
Render the table schema to an array of statements
public
renderToStatements() : array<string|int, mixed>
Return values
array<string|int, mixed>setIdQuoteType()
Set the quote ID type
public
setIdQuoteType([string $type = self::NO_QUOTE ]) : AbstractSql
Parameters
- $type : string = self::NO_QUOTE
Return values
AbstractSqlsetPlaceholder()
Set the placeholder
public
setPlaceholder(string $placeholder) : AbstractSql
Parameters
- $placeholder : string
Return values
AbstractSqlsmallInt()
Add a SMALLINT column
public
smallInt(string $name[, mixed $size = null ][, array<string|int, mixed> $attributes = [] ]) : AbstractStructure
Parameters
- $name : string
- $size : mixed = null
- $attributes : array<string|int, mixed> = []
Return values
AbstractStructuretext()
Add a TEXT column
public
text(string $name[, array<string|int, mixed> $attributes = [] ]) : AbstractStructure
Parameters
- $name : string
- $attributes : array<string|int, mixed> = []
Return values
AbstractStructuretime()
Add a TIME column
public
time(string $name[, array<string|int, mixed> $attributes = [] ]) : AbstractStructure
Parameters
- $name : string
- $attributes : array<string|int, mixed> = []
Return values
AbstractStructuretimestamp()
Add a TIMESTAMP column
public
timestamp(string $name[, array<string|int, mixed> $attributes = [] ]) : AbstractStructure
Parameters
- $name : string
- $attributes : array<string|int, mixed> = []
Return values
AbstractStructuretinyInt()
Add a TINYINT column
public
tinyInt(string $name[, mixed $size = null ][, array<string|int, mixed> $attributes = [] ]) : AbstractStructure
Parameters
- $name : string
- $size : mixed = null
- $attributes : array<string|int, mixed> = []
Return values
AbstractStructuretinyText()
Add a TINYTEXT column
public
tinyText(string $name[, array<string|int, mixed> $attributes = [] ]) : AbstractStructure
Parameters
- $name : string
- $attributes : array<string|int, mixed> = []
Return values
AbstractStructureunique()
Create a UNIQUE index
public
unique([string|array<string|int, mixed>|null $column = null ][, string|null $name = null ]) : AbstractStructure
Parameters
- $column : string|array<string|int, mixed>|null = null
- $name : string|null = null
Return values
AbstractStructureunsigned()
Set the current column as unsigned
public
unsigned() : AbstractStructure
Return values
AbstractStructurevarchar()
Add a VARCHAR column
public
varchar(string $name[, int $size = null ][, array<string|int, mixed> $attributes = [] ]) : AbstractStructure
Parameters
- $name : string
- $size : int = null
- $attributes : array<string|int, mixed> = []
Return values
AbstractStructureyear()
Add a YEAR column
public
year(string $name[, mixed $size = null ][, array<string|int, mixed> $attributes = [] ]) : AbstractStructure
Parameters
- $name : string
- $size : mixed = null
- $attributes : array<string|int, mixed> = []
Return values
AbstractStructuregetColumnSchema()
Format column schema
protected
getColumnSchema(string $name, array<string|int, mixed> $column) : string
Parameters
- $name : string
- $column : array<string|int, mixed>
Return values
stringinit()
Initialize SQL object
protected
init(string $adapter) : void
Parameters
- $adapter : string
initQuoteType()
Initialize quite type
protected
initQuoteType() : void