fyre/schema

A database schema library.

v3.1.2 2024-06-25 06:30 UTC

README

FyreSchema

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;

Schema Registry

Get Cache

Get the Cacher.

$cache = SchemaRegistry::getCache();

Get Schema

Get the Schema for a Connection.

$schema = SchemaRegistry::getSchema($connection);

Set Cache

Set the Cacher.

SchemaRegistry::getCache($cache);

Set Handler

Set a Schema handler for a Connection class.

  • $connectionClass is a string representing the Connection class name.
  • $schemaClass is a string representing the Schema class name.
SchemaRegistry::setHandler($connectionClass, $schemaClass);

Schemas

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);

Get Connection

Get the Connection.

$connection = $schema->getConnection();

Get Database Name

Get the database name.

$database = $schema->getDatabaseName();

Has Table

Determine if 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();

Table Schemas

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 Column

Determine if the table has a column.

  • $name is a string representing the column name.
$hasColumn = $tableSchema->hasColumn($name);

Has Foreign Key

Determine if the table has a foreign key.

  • $name is a string representing the foreign key name.
$hasForeignKey = $tableSchema->hasForeignKey($name);

Has Index

Determine if 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 if 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();