hectororm / schema
Hector Schema
Installs: 3 757
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: ^8.0
- ext-pdo: *
- hectororm/connection: v1.0.0-beta7
Requires (Dev)
- ext-pdo_mysql: *
- ext-pdo_sqlite: *
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2024-11-25 15:29:27 UTC
README
Hector Schema is the schema generator module of Hector ORM. Can be used independently of ORM.
Installation
Composer
You can install Hector Schema with Composer, it's the recommended installation.
$ composer require hectororm/schema
Dependencies
- PHP ^8.0
- Packages dependencies:
- hectororm/connection
DBMS compatibility
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\MySQL
for MySQL or derived DBMSHector\Schema\Generato\Sqlite
for 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): Generator
Returns a generator ofHector\Schema\Schema
objects, you can pass a specific connectionSchemaContainer::hasSchema(string $name, ?string $connection = null): bool
Check if container has a schemaSchemaContainer::getSchema(string $name, ?string $connection = null): Schema
Returns representation of a schema, anHector\Schema\Schema
objectSchemaContainer::hasTable(string $name, ?string $schemaName = null, ?string $connection = null): bool
Check if a schema in the container has a tableSchemaContainer::getTable(string $name, ?string $schemaName = null, ?string $connection = null): Table
Returns representation of a table, anHector\Schema\Table
object
It's an iterable class, returns Hector\Schema\Schema
objects.
Hector\Schema\Schema
Represent a schema. Methods available:
Schema::getName(bool $quoted = false): string
Returns the name of schemaSchema::getCharset(): string
Returns the charset of schemaSchema::getCollation(): string
Returns the charset of schemaSchema::getTables(): Generator
Returns a generator ofHector\Schema\Table
objectsSchema::hasTable(string $name): bool
Check if schema has a tableSchema::getTable(string $name): Table
Returns representation of a table, anHector\Schema\Table
objectSchema::getContainer(): ?SchemaContainer
Returns 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): string
Table::getName(bool $quoted = false): string
Table::getFullName(bool $quoted = false): string
Table::getType(): string
Table::getCharset(): ?string
Table::getCollation(): ?string
Table::getColumns(): Generator
Table::getColumnsName(bool $quoted = false, ?string $tableAlias = null): array
Table::hasColumn(string $name): bool
Table::getColumn(string $name): Column
Table::getAutoIncrementColumn(): ?Column
Table::getIndexes(?string $type = null): Generator
Table::hasIndex(string $name): bool
Table::getIndex(string $name): Index
Table::getPrimaryIndex(): ?Index
Table::getForeignKeys(Table $table = null): Generator
Table::getSchema(): Schema
Hector\Schema\Column
Represent a column of a table. Methods available:
Column::getName(bool $quoted = false, ?string $tableAlias = null): string
Column::getFullName(bool $quoted = false): string
Column::getPosition(): int
Column::getDefault(): mixed
Column::isNullable(): bool
Column::getType(): string
Column::isAutoIncrement(): bool
Column::getMaxlength(): ?int
Column::getNumericPrecision(): ?int
Column::getNumericScale(): ?int
Column::isUnsigned(): bool
Column::getCharset(): ?string
Column::getCollation(): ?string
Column::getTable(): Table
Column::isPrimary(): bool
Hector\Schema\Index
Represent an index of a table. Methods available:
Index::getName(): string
Index::getType(): string
Index::getColumnsName(bool $quoted = false, ?string $tableAlias = null): array
Index::getTable(): Table
Index::getColumns(): array
Index::hasColumn(Column $column): bool
Hector\Schema\ForeignKey
Represent a foreign key of a table. Methods available:
ForeignKey::getName(): string
ForeignKey::getColumnsName(bool $quoted = false, ?string $tableAlias = null): array
ForeignKey::getReferencedSchemaName(): string
ForeignKey::getReferencedTableName(): string
ForeignKey::getReferencedColumnsName(bool $quoted = false, ?string $tableAlias = null): array
ForeignKey::getUpdateRule(): string
ForeignKey::getDeleteRule(): string
ForeignKey::getTable(): Table
ForeignKey::getColumns(): Generator
ForeignKey::getReferencedTable(): ?Table
ForeignKey::getReferencedColumns(): Generator