fyre / schema
A database schema library.
Requires
- fyre/cache: ^5.0
- fyre/collection: ^1.0
- fyre/container: ^1.0
- fyre/db: ^6.0
- fyre/macro: ^1.0
- fyre/typeparser: ^5.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.59
- fyre/php-cs-fixer-config: ^1.0
- phpunit/phpunit: ^12
- dev-main
- v7.0
- v6.0.13
- v6.0.12
- v6.0.11
- v6.0.10
- v6.0.9
- v6.0.8
- v6.0.7
- v6.0.6
- v6.0.5
- v6.0.4
- v6.0.3
- 6.0.2
- v6.0.1
- v6.0
- v5.0.1
- v5.0
- v4.2.4
- v4.2.3
- v4.2.2
- v4.2.1
- v4.2.0
- v4.1.0
- v4.0.2
- v4.0.1
- v4.0
- v3.1.2
- v3.1.1
- v3.1.0
- v3.0.1
- v3.0
- v2.0.5
- v2.0.4
- v2.0.3
- v2.0.2
- v2.0.1
- v2.0
- v1.1.2
- v1.1.1
- v1.1.0
- v1.0.8
- v1.0.7
- v1.0.6
- v1.0.5
- v1.0.4
- v1.0.3
- v1.0.2
- v1.0.1
- v1.0
This package is auto-updated.
Last update: 2025-09-07 01:37:38 UTC
README
FyreSchema is a free, open-source database schema library for PHP.
Table Of Contents
Installation
Using Composer
composer require fyre/schema
In PHP:
use Fyre\Schema\SchemaRegistry;
Basic Usage
$container
is 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);
Methods
Map
Map a Connection class to a Schema handler.
$connectionClass
is a string representing the Connection class name.$schemaClass
is a string representing the Schema class name.
$schemaRegistry->map($connectionClass, $schemaClass);
Use
Load the shared Schema for a Connection.
$connection
is a Connection.
$schema = $schemaRegistry->use($connection);
Schema dependencies will be resolved automatically from the Container.
Schemas
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.
$name
is a string representing the table name.
$hasTable = $schema->hasTable($name);
Table
Load a Table.
$name
is 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.
Tables
Clear
Clear the table data (including cache).
$table->clear();
Column
Load a Column.
$name
is 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.
$name
is 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.
$name
is a string representing the column name.
$hasColumn = $table->hasColumn($name);
Has Foreign Key
Determine whether the table has a foreign key.
$name
is a string representing the foreign key name.
$hasForeignKey = $table->hasForeignKey($name);
Has Index
Determine whether the table has an index.
$name
is a string representing the index name.
$hasIndex = $table->hasIndex($name);
Index
Load an Index.
$name
is 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();
Mysql Tables
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();
Columns
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();
Mysql Columns
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();
Indexes
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->getData();
Foreign Keys
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->getReferencesTable();
Get Table
Get the Table.
$table = $foreignKey->getTable();
To Array
Get the foreign key data as an array.
$data = $foreignKey->toArray();