hectororm / schema
Hector Schema
v1.0.0-beta7
2024-03-19 15:57 UTC
Requires
- php: ^8.0
- ext-pdo: *
- hectororm/connection: v1.0.0-beta6
Requires (Dev)
- ext-pdo_mysql: *
- ext-pdo_sqlite: *
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2024-09-19 16:58:13 UTC
README
Hector Schema 是 Hector ORM 的模式生成模块。它可以独立于 ORM 使用。
安装
Composer
您可以使用 Composer 安装 Hector Schema,这是推荐的安装方法。
$ composer require hectororm/schema
依赖关系
- PHP ^8.0
- 包依赖关系
- hectororm/connection
数据库管理系统兼容性
如果您有关于其他版本兼容性的信息,请随时提交 PR。
使用
生成模式
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
生成器
Hector\Schema\Generato\MySQL用于 MySQL 或其派生的数据库管理系统Hector\Schema\Generato\Sqlite用于 Sqlite
缓存
此库不提供模式缓存管理。用户库需要自行考虑如何存储生成的模式。
为此,库仅提供对象的序列化和对象继承的恢复。
模式
类的描述表示一个模式。
Hector\Schema\SchemaContainer
它是模式容器。可用方法
SchemaContainer::getSchemas(?string $connection = null): Generator返回Hector\Schema\Schema对象生成器,您可以传递一个特定的连接SchemaContainer::hasSchema(string $name, ?string $connection = null): bool检查容器是否有模式SchemaContainer::getSchema(string $name, ?string $connection = null): Schema返回模式的表示,一个Hector\Schema\Schema对象SchemaContainer::hasTable(string $name, ?string $schemaName = null, ?string $connection = null): bool检查容器中是否有表SchemaContainer::getTable(string $name, ?string $schemaName = null, ?string $connection = null): Table返回表的表示,一个Hector\Schema\Table对象
它是一个可迭代的类,返回 Hector\Schema\Schema 对象。
Hector\Schema\Schema
代表一个模式。可用方法
Schema::getName(bool $quoted = false): string返回模式的名称Schema::getCharset(): string返回模式的字符集Schema::getCollation(): string返回模式的校对规则Schema::getTables(): Generator返回Hector\Schema\Table对象生成器Schema::hasTable(string $name): bool检查模式是否有表Schema::getTable(string $name): Table返回表的表示,一个Hector\Schema\Table对象Schema::getContainer(): ?SchemaContainer如果模式是容器的一部分,则返回模式的容器
它是一个可迭代的类,返回 Hector\Schema\Table 对象。
Hector\Schema\Table
代表模式中的表。可用方法
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): 生成器Table::getSchema(): Schema
Hector\Schema\Column
表示表中的一列。可用方法:
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
表示表中的一个索引。可用方法:
Index::getName(): stringIndex::getType(): stringIndex::getColumnsName(bool $quoted = false, ?string $tableAlias = null): arrayIndex::getTable(): TableIndex::getColumns(): arrayIndex::hasColumn(Column $column): bool
Hector\Schema\ForeignKey
表示表中的一个外键。可用方法:
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(): 生成器ForeignKey::getReferencedTable(): ?TableForeignKey::getReferencedColumns(): 生成器