hectororm/schema

v1.0.0-beta7 2024-03-19 15:57 UTC

This package is auto-updated.

Last update: 2024-09-19 16:58:13 UTC


README

Latest Version Software license Build Status Quality Grade Total Downloads

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): 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): 生成器
  • Table::getSchema(): Schema

Hector\Schema\Column

表示表中的一列。可用方法:

  • 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

表示表中的一个索引。可用方法:

  • 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

表示表中的一个外键。可用方法:

  • 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(): 生成器
  • ForeignKey::getReferencedTable(): ?Table
  • ForeignKey::getReferencedColumns(): 生成器