FyreSchema is a free, open-source database schema library for PHP.
Using Composer
composer require fyre/schema
In PHP:
use Fyre\Schema\SchemaRegistry;$containeris a Container.
$schemaRegistry = new SchemaRegistry($container);Autoloading
It is recommended to bind the SchemaRegistry to the Container as a singleton.
$container->singleton(SchemaRegistry::class);Any dependencies will be injected automatically when loading from the Container.
$schemaRegistry = $container->use(SchemaRegistry::class);Map
Map a Connection class to a Schema handler.
$connectionClassis a string representing the Connection class name.$schemaClassis a string representing the Schema class name.
$schemaRegistry->map($connectionClass, $schemaClass);Use
Load the shared Schema for a Connection.
$connectionis a Connection.
$schema = $schemaRegistry->use($connection);Schema dependencies will be resolved automatically from the Container.
Clear
Clear the table data (including cache).
$schema->clear();Get Connection
Get the Connection.
$connection = $schema->getConnection();Get Database Name
Get the database name.
$database = $schema->getDatabaseName();Has Table
Determine whether the schema has a table.
$nameis a string representing the table name.
$hasTable = $schema->hasTable($name);Table
Load a Table.
$nameis a string representing the table name.
$table = $schema->table($name);Table Names
Get the names of all schema tables.
$tableNames = $schema->tableNames();Tables
Load all schema tables.
$tables = $schema->tables();This method will return a Collection containing the loaded tables.
Clear
Clear the table data (including cache).
$table->clear();Column
Load a Column.
$nameis a string representing the column name.
$column = $table->column($name);Column Names
Get the names of all table columns.
$columnNames = $table->columnNames();Columns
Load all table columns.
$columns = $table->columns();This method will return a Collection containing the loaded columns.
Foreign Key
Load a ForeignKey.
$nameis a string representing the foreign key name.
$foreignKey = $table->foreignKey($name);Foreign Keys
Load all table foreign keys.
$foreignKeys = $table->foreignKeys();This method will return a Collection containing the loaded foreign keys.
Get Comment
Get the table comment.
$comment = $table->getComment();Get Name
Get the table name.
$name = $table->getName();Get Schema
Get the Schema.
$schema = $table->getSchema();Has Auto Increment
Determine whether the table has an auto increment column.
$hasAutoIncrement = $table->hasAutoIncrement();Has Column
Determine whether the table has a column.
$nameis a string representing the column name.
$hasColumn = $table->hasColumn($name);Has Foreign Key
Determine whether the table has a foreign key.
$nameis a string representing the foreign key name.
$hasForeignKey = $table->hasForeignKey($name);Has Index
Determine whether the table has an index.
$nameis a string representing the index name.
$hasIndex = $table->hasIndex($name);Index
Load an Index.
$nameis a string representing the index name.
$index = $table->index($name);Indexes
Load all table indexes.
$indexes = $table->indexes();This method will return a Collection containing the loaded indexes.
Primary Key
Get the primary key for the table.
$primaryKey = $table->primaryKey();To Array
Get the table data as an array.
$data = $table->toArray();Get Charset
Get the table character set.
$charset = $table->getCharset();Get Collation
Get the table collation.
$collation = $table->getCollation();Get Engine
Get the table engine.
$engine = $table->getEngine();Default Value
Get the evaluated default value for a column.
$defaultValue = $column->defaultValue();Get Comment
Get the column comment.
$comment = $column->getComment();Get Default
Get the column default value.
$default = $column->getDefault();Get Length
Get the column length.
$length = $column->getLength();Get Name
Get the column name.
$name = $column->getName();Get Precision
Get the column precision.
$precision = $column->getPrecision();Get Table
Get the Table.
$table = $column->getTable();Get Type
Get the column type.
$type = $column->getType();Is Auto Increment
Determine whether the column is an auto increment column.
$isAutoIncrement = $column->isAutoIncrement();Is Nullable
Determine whether the column is nullable.
$isNullable = $column->isNullable();Is Unsigned
Determine whether the column is unsigned.
$isUnsigned = $column->isUnsigned();To Array
Get the column data as an array.
$data = $column->toArray();Type
Get the type parser for the column.
$typeParser = $column->type();Get Charset
Get the column character set.
$charset = $column->getCharset();Get Collation
Get the column collation.
$collation = $column->getCollation();Get Values
Get the column enum values.
$values = $column->getValues();Get Columns
Get the column names.
$columns = $index->getColumns();Get Name
Get the index name.
$name = $index->getName();Get Table
Get the Table.
$table = $index->getTable();Get Type
Get the index type.
$type = $index->getType();Is Primary
Determine whether the index is primary.
$isPrimary = $index->isPrimary();Is Unique
Determine whether the index is unique.
$isUnique = $index->isUnique();To Array
Get the index data as an array.
$data = $index->toArray();Get Columns
Get the column names.
$columns = $foreignKey->getColumns();Get Name
Get the foreign key name.
$name = $foreignKey->getName();Get On Delete
Get the delete action.
$onDelete = $foreignKey->getOnDelete();Get On Update
Get the update action.
$onUpdate = $foreignKey->getOnUpdate();Get Referenced Columns
Get the referenced column names.
$referencedColumn = $foreignKey->getReferencedColumns();Get Referenced Table
Get the referenced table name.
$referencedTable = $foreignKey->getReferencedTable();Get Table
Get the Table.
$table = $foreignKey->getTable();To Array
Get the foreign key data as an array.
$data = $foreignKey->toArray();