hectororm / schema
Hector Schema
Installs: 5 266
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
pkg:composer/hectororm/schema
Requires
- php: ^8.0
- ext-pdo: *
- hectororm/connection: ^1.0
This package is auto-updated.
Last update: 2025-10-26 16:45:30 UTC
README
Note
This repository is a read-only split from the main HectorORM repository.
For contributions, issues, or more information, please visit the main HectorORM repository.
Do not open issues or pull requests here.
Hector Schema is the schema generator module of Hector ORM. Can be used independently of ORM.
Installation
You can install Hector Schema with Composer, it's the recommended installation.
$ composer require hectororm/schema
DBMS compatibility
| DBMS | Version | Compatibility |
|---|---|---|
| MySQL | 8.4 | ✔ |
| MySQL | 8.0 | ✔ |
| MySQL | 5.7 | ✔ |
| MariaDB | 11.7 | ✔ |
| MariaDB | 11.4 | ✔ |
| MariaDB | 10.11 | ✔ |
| MariaDB | 10.6 | ✔ |
| MariaDB | 10.5 | ✔ |
| Sqlite | 3.x | ✔ |
If you have any information on the compatibility of other versions, feel free to make a PR.
Usage
Generate a schema
use Hector\Connection\Connection; use Hector\Schema\Generator\MySQL; $connection = new Connection('...'); $generator = new MySQL($connection); $schema = $generator->generateSchema('schema_name'); // Returns a `Hector\Schema\Schema` object $container = $generator->generateSchemas('schema1_name', 'schema2_name'); // Returns a `Hector\Schema\SchemaContainer` object
Generators:
Hector\Schema\Generato\MySQLfor MySQL or derived DBMSHector\Schema\Generato\Sqlitefor Sqlite
Cache
This library don't provide cache management for schemas. It's to the user library to imagine how store the generated schema.
To help to do that, library only provide serialization of objects and restoration of inheritance between objects.
Schema
Description of classes represents the a schema.
Hector\Schema\SchemaContainer
It's a container of schema. Methods available:
SchemaContainer::getSchemas(?string $connection = null): GeneratorReturns a generator ofHector\Schema\Schemaobjects, you can pass a specific connectionSchemaContainer::hasSchema(string $name, ?string $connection = null): boolCheck if container has a schemaSchemaContainer::getSchema(string $name, ?string $connection = null): SchemaReturns representation of a schema, anHector\Schema\SchemaobjectSchemaContainer::hasTable(string $name, ?string $schemaName = null, ?string $connection = null): boolCheck if a schema in the container has a tableSchemaContainer::getTable(string $name, ?string $schemaName = null, ?string $connection = null): TableReturns representation of a table, anHector\Schema\Tableobject
It's an iterable class, returns Hector\Schema\Schema objects.
Hector\Schema\Schema
Represent a schema. Methods available:
Schema::getName(bool $quoted = false): stringReturns the name of schemaSchema::getCharset(): stringReturns the charset of schemaSchema::getCollation(): stringReturns the charset of schemaSchema::getTables(): GeneratorReturns a generator ofHector\Schema\TableobjectsSchema::hasTable(string $name): boolCheck if schema has a tableSchema::getTable(string $name): TableReturns representation of a table, anHector\Schema\TableobjectSchema::getContainer(): ?SchemaContainerReturns the container of schema if it's a part of a container
It's an iterable class, returns Hector\Schema\Table objects.
Hector\Schema\Table
Represent a table of a schema. Methods available:
Table::getSchemaName(bool $quoted = false): stringTable::getName(bool $quoted = false): stringTable::getFullName(bool $quoted = false): stringTable::getType(): stringTable::getCharset(): ?stringTable::getCollation(): ?stringTable::getColumns(): GeneratorTable::getColumnsName(bool $quoted = false, ?string $tableAlias = null): arrayTable::hasColumn(string $name): boolTable::getColumn(string $name): ColumnTable::getAutoIncrementColumn(): ?ColumnTable::getIndexes(?string $type = null): GeneratorTable::hasIndex(string $name): boolTable::getIndex(string $name): IndexTable::getPrimaryIndex(): ?IndexTable::getForeignKeys(Table $table = null): GeneratorTable::getSchema(): Schema
Hector\Schema\Column
Represent a column of a table. Methods available:
Column::getName(bool $quoted = false, ?string $tableAlias = null): stringColumn::getFullName(bool $quoted = false): stringColumn::getPosition(): intColumn::getDefault(): mixedColumn::isNullable(): boolColumn::getType(): stringColumn::isAutoIncrement(): boolColumn::getMaxlength(): ?intColumn::getNumericPrecision(): ?intColumn::getNumericScale(): ?intColumn::isUnsigned(): boolColumn::getCharset(): ?stringColumn::getCollation(): ?stringColumn::getTable(): TableColumn::isPrimary(): bool
Hector\Schema\Index
Represent an index of a table. Methods available:
Index::getName(): stringIndex::getType(): stringIndex::getColumnsName(bool $quoted = false, ?string $tableAlias = null): arrayIndex::getTable(): TableIndex::getColumns(): arrayIndex::hasColumn(Column $column): bool
Hector\Schema\ForeignKey
Represent a foreign key of a table. Methods available:
ForeignKey::getName(): stringForeignKey::getColumnsName(bool $quoted = false, ?string $tableAlias = null): arrayForeignKey::getReferencedSchemaName(): stringForeignKey::getReferencedTableName(): stringForeignKey::getReferencedColumnsName(bool $quoted = false, ?string $tableAlias = null): arrayForeignKey::getUpdateRule(): stringForeignKey::getDeleteRule(): stringForeignKey::getTable(): TableForeignKey::getColumns(): GeneratorForeignKey::getReferencedTable(): ?TableForeignKey::getReferencedColumns(): Generator