FyreSchema is a free, open-source database schema library for PHP.
Using Composer
composer require fyre/schema
In PHP:
use Fyre\Schema\SchemaRegistry;
$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);
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.
Clear
Clear data from the cache.
$schema->clear();
Describe
Get the TableSchema for a table.
$name
is a string representing the table name.
$tableSchema = $schema->describe($name);
TableSchema dependencies will be resolved automatically from the Container.
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
Get the data for 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
Get the data for all schema tables.
$tables = $schema->tables();
Clear
Clear data from the cache.
$tableSchema->clear();
Column
Get the data for a table column.
$name
is a string representing the column name.
$column = $tableSchema->column($name);
Column Names
Get the names of all table columns.
$columnNames = $tableSchema->columnNames();
Columns
Get the data for all table columns.
$columns = $tableSchema->columns();
Default Value
Get the default value for a column.
$name
is a string representing the column name.
$defaultValue = $tableSchema->defaultValue($name);
This method will evaluate expression values (eg. current_timestamp()).
Foreign Key
Get the data for a table foreign key.
$name
is a string representing the foreign key name.
$foreignKey = $tableSchema->foreignKey($name);
Foreign Keys
Get the data for all table foreign keys.
$foreignKeys = $tableSchema->foreignKeys();
Get Schema
Get the Schema.
$schema = $tableSchema->getSchema();
Get Table Name
Get the table name.
$tableName = $tableSchema->getTableName();
Get Type
Get the Type parser for a column.
$name
is a string representing the column name.
$parser = $tableSchema->getType($name);
Has Auto Increment
Determine whether the table has an auto increment column.
$hasAutoIncrement = $tableSchema->hasAutoIncrement();
Has Column
Determine whether the table has a column.
$name
is a string representing the column name.
$hasColumn = $tableSchema->hasColumn($name);
Has Foreign Key
Determine whether the table has a foreign key.
$name
is a string representing the foreign key name.
$hasForeignKey = $tableSchema->hasForeignKey($name);
Has Index
Determine whether the table has an index.
$name
is a string representing the index name.
$hasIndex = $tableSchema->hasIndex($name);
Index
Get the data for a table index.
$name
is a string representing the index name.
$index = $tableSchema->index($name);
Indexes
Get the data for all table indexes.
$indexes = $tableSchema->indexes();
Is Nullable
Determine whether a table column is nullable.
$name
is a string representing the column name.
$isNullable = $tableSchema->isNullable($name);
Primary Key
Get the primary key for the table.
$primaryKey = $tableSchema->primaryKey();