Table
    
            
            in package
            
        
    
    
    
Provides missing features for altering tables that are common in other supported databases, but are missing from SQLite.
These are needed in order to support migrations during testing when another database is used as the primary engine, but SQLite in memory databases are used for faster test execution.
Table of Contents
Properties
- $db : Connection
- Database connection.
- $fields : array<string, array<string, bool|int|string|null>>
- All of the fields this table represents.
- $foreignKeys : array<string|int, mixed>
- All of the foreign keys in the table.
- $forge : Forge
- Handle to our forge.
- $keys : array<string|int, mixed>
- All of the unique/primary keys in the table.
- $prefixedTableName : string
- The name of the table, with database prefix
- $tableName : string
- The name of the table we're working with.
Methods
- __construct() : mixed
- Table constructor.
- addForeignKey() : $this
- Add a foreign key
- addPrimaryKey() : Table
- Adds primary key
- dropColumn() : Table
- Drops columns from the table.
- dropForeignKey() : Table
- Drops a foreign key from this table so that it won't be recreated in the future.
- dropPrimaryKey() : Table
- Drops the primary key
- fromTable() : Table
- Reads an existing database table and collects all of the information needed to recreate this table.
- modifyColumn() : Table
- Modifies a field, including changing data type, renaming, etc.
- run() : bool
- Called after `fromTable` and any actions, like `dropColumn`, etc, to finalize the action. It creates a temp table, creates the new table with modifications, and copies the data over to the new table.
- copyData() : void
- Copies data from our old table to the new one, taking care map data correctly based on any columns that have been renamed.
- createTable() : bool
- Creates the new table based on our current fields.
- dropIndexes() : void
- Attempts to drop all indexes and constraints from the database for this table.
- formatFields() : mixed
- Converts fields retrieved from the database to the format needed for creating fields with Forge.
- formatKeys() : array<string, array{fields: string, type: string}>
- Converts keys retrieved from the database to the format needed to create later.
- isIntegerType() : bool
- Is INTEGER type?
- isNumericType() : bool
- Is NUMERIC type?
Properties
$db
Database connection.
        protected
            Connection
    $db
    
    
    
    
    
    
$fields
All of the fields this table represents.
        protected
            array<string, array<string, bool|int|string|null>>
    $fields
     = []
    
        [name => attributes]
$foreignKeys
All of the foreign keys in the table.
        protected
            array<string|int, mixed>
    $foreignKeys
     = []
    
    
    
    
    
$forge
Handle to our forge.
        protected
            Forge
    $forge
    
    
    
    
    
    
$keys
All of the unique/primary keys in the table.
        protected
            array<string|int, mixed>
    $keys
     = []
    
    
    
    
    
$prefixedTableName
The name of the table, with database prefix
        protected
            string
    $prefixedTableName
    
    
    
    
    
    
$tableName
The name of the table we're working with.
        protected
            string
    $tableName
    
    
    
    
    
    
Methods
__construct()
Table constructor.
    public
                    __construct(Connection $db, Forge $forge) : mixed
    Parameters
- $db : Connection
- $forge : Forge
addForeignKey()
Add a foreign key
    public
                    addForeignKey(array<string|int, mixed> $foreignKeys) : $this
    Parameters
- $foreignKeys : array<string|int, mixed>
Return values
$thisaddPrimaryKey()
Adds primary key
    public
                    addPrimaryKey(array<string|int, mixed> $fields) : Table
    Parameters
- $fields : array<string|int, mixed>
Return values
TabledropColumn()
Drops columns from the table.
    public
                    dropColumn(array<int, string>|string $columns) : Table
    Parameters
- $columns : array<int, string>|string
- 
                    Column names to drop. 
Return values
TabledropForeignKey()
Drops a foreign key from this table so that it won't be recreated in the future.
    public
                    dropForeignKey(string $foreignName) : Table
    Parameters
- $foreignName : string
Return values
TabledropPrimaryKey()
Drops the primary key
    public
                    dropPrimaryKey() : Table
    Return values
TablefromTable()
Reads an existing database table and collects all of the information needed to recreate this table.
    public
                    fromTable(string $table) : Table
    Parameters
- $table : string
Return values
TablemodifyColumn()
Modifies a field, including changing data type, renaming, etc.
    public
                    modifyColumn(array<int, array<string, bool|int|string|null>> $fieldsToModify) : Table
    Parameters
- $fieldsToModify : array<int, array<string, bool|int|string|null>>
Return values
Tablerun()
Called after `fromTable` and any actions, like `dropColumn`, etc, to finalize the action. It creates a temp table, creates the new table with modifications, and copies the data over to the new table.
    public
                    run() : bool
    Resets the connection dataCache to be sure changes are collected.
Return values
boolcopyData()
Copies data from our old table to the new one, taking care map data correctly based on any columns that have been renamed.
    protected
                    copyData() : void
    createTable()
Creates the new table based on our current fields.
    protected
                    createTable() : bool
    Return values
booldropIndexes()
Attempts to drop all indexes and constraints from the database for this table.
    protected
                    dropIndexes() : void
    formatFields()
Converts fields retrieved from the database to the format needed for creating fields with Forge.
    protected
                    formatFields(array<string|int, mixed>|bool $fields) : mixed
    Parameters
- $fields : array<string|int, mixed>|bool
formatKeys()
Converts keys retrieved from the database to the format needed to create later.
    protected
                    formatKeys(array<string, stdClass> $keys) : array<string, array{fields: string, type: string}>
    Parameters
- $keys : array<string, stdClass>
Return values
array<string, array{fields: string, type: string}>isIntegerType()
Is INTEGER type?
    private
                    isIntegerType(string $type) : bool
    Parameters
- $type : string
- 
                    SQLite data type (case-insensitive) 
Tags
Return values
boolisNumericType()
Is NUMERIC type?
    private
                    isNumericType(string $type) : bool
    Parameters
- $type : string
- 
                    SQLite data type (case-insensitive)