fyre/schema
Composer 安装命令:
composer require fyre/schema
包简介
A database schema library.
README 文档
README
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;
Basic Usage
$containeris a Container.
$schemaRegistry = new SchemaRegistry($container);
Autoloading
It is recommended to bind the SchemaRegistry to the Container as a singleton.
$container->singleton(SchemaRegistry::class);
Any dependencies will be injected automatically when loading from the Container.
$schemaRegistry = $container->use(SchemaRegistry::class);
Methods
Map
Map a Connection class to a Schema handler.
$connectionClassis a string representing the Connection class name.$schemaClassis a string representing the Schema class name.
$schemaRegistry->map($connectionClass, $schemaClass);
Use
Load the shared Schema for a Connection.
$connectionis a Connection.
$schema = $schemaRegistry->use($connection);
Schema dependencies will be resolved automatically from the Container.
Schemas
Clear
Clear the table data (including cache).
$schema->clear();
Get Connection
Get the Connection.
$connection = $schema->getConnection();
Get Database Name
Get the database name.
$database = $schema->getDatabaseName();
Has Table
Determine whether the schema has a table.
$nameis a string representing the table name.
$hasTable = $schema->hasTable($name);
Table
Load a Table.
$nameis a string representing the table name.
$table = $schema->table($name);
Table Names
Get the names of all schema tables.
$tableNames = $schema->tableNames();
Tables
Load all schema tables.
$tables = $schema->tables();
This method will return a Collection containing the loaded tables.
Tables
Clear
Clear the table data (including cache).
$table->clear();
Column
Load a Column.
$nameis a string representing the column name.
$column = $table->column($name);
Column Names
Get the names of all table columns.
$columnNames = $table->columnNames();
Columns
Load all table columns.
$columns = $table->columns();
This method will return a Collection containing the loaded columns.
Foreign Key
Load a ForeignKey.
$nameis a string representing the foreign key name.
$foreignKey = $table->foreignKey($name);
Foreign Keys
Load all table foreign keys.
$foreignKeys = $table->foreignKeys();
This method will return a Collection containing the loaded foreign keys.
Get Comment
Get the table comment.
$comment = $table->getComment();
Get Name
Get the table name.
$name = $table->getName();
Get Schema
Get the Schema.
$schema = $table->getSchema();
Has Auto Increment
Determine whether the table has an auto increment column.
$hasAutoIncrement = $table->hasAutoIncrement();
Has Column
Determine whether the table has a column.
$nameis a string representing the column name.
$hasColumn = $table->hasColumn($name);
Has Foreign Key
Determine whether the table has a foreign key.
$nameis a string representing the foreign key name.
$hasForeignKey = $table->hasForeignKey($name);
Has Index
Determine whether the table has an index.
$nameis a string representing the index name.
$hasIndex = $table->hasIndex($name);
Index
Load an Index.
$nameis a string representing the index name.
$index = $table->index($name);
Indexes
Load all table indexes.
$indexes = $table->indexes();
This method will return a Collection containing the loaded indexes.
Primary Key
Get the primary key for the table.
$primaryKey = $table->primaryKey();
To Array
Get the table data as an array.
$data = $table->toArray();
MySQL Tables
Get Charset
Get the table character set.
$charset = $table->getCharset();
Get Collation
Get the table collation.
$collation = $table->getCollation();
Get Engine
Get the table engine.
$engine = $table->getEngine();
Columns
Default Value
Get the evaluated default value for a column.
$defaultValue = $column->defaultValue();
Get Comment
Get the column comment.
$comment = $column->getComment();
Get Default
Get the column default value.
$default = $column->getDefault();
Get Length
Get the column length.
$length = $column->getLength();
Get Name
Get the column name.
$name = $column->getName();
Get Precision
Get the column precision.
$precision = $column->getPrecision();
Get Table
Get the Table.
$table = $column->getTable();
Get Type
Get the column type.
$type = $column->getType();
Is Auto Increment
Determine whether the column is an auto increment column.
$isAutoIncrement = $column->isAutoIncrement();
Is Nullable
Determine whether the column is nullable.
$isNullable = $column->isNullable();
Is Unsigned
Determine whether the column is unsigned.
$isUnsigned = $column->isUnsigned();
To Array
Get the column data as an array.
$data = $column->toArray();
Type
Get the type parser for the column.
$typeParser = $column->type();
MySQL Columns
Get Charset
Get the column character set.
$charset = $column->getCharset();
Get Collation
Get the column collation.
$collation = $column->getCollation();
Get Values
Get the column enum values.
$values = $column->getValues();
Indexes
Get Columns
Get the column names.
$columns = $index->getColumns();
Get Name
Get the index name.
$name = $index->getName();
Get Table
Get the Table.
$table = $index->getTable();
Get Type
Get the index type.
$type = $index->getType();
Is Primary
Determine whether the index is primary.
$isPrimary = $index->isPrimary();
Is Unique
Determine whether the index is unique.
$isUnique = $index->isUnique();
To Array
Get the index data as an array.
$data = $index->toArray();
Foreign Keys
Get Columns
Get the column names.
$columns = $foreignKey->getColumns();
Get Name
Get the foreign key name.
$name = $foreignKey->getName();
Get On Delete
Get the delete action.
$onDelete = $foreignKey->getOnDelete();
Get On Update
Get the update action.
$onUpdate = $foreignKey->getOnUpdate();
Get Referenced Columns
Get the referenced column names.
$referencedColumn = $foreignKey->getReferencedColumns();
Get Referenced Table
Get the referenced table name.
$referencedTable = $foreignKey->getReferencedTable();
Get Table
Get the Table.
$table = $foreignKey->getTable();
To Array
Get the foreign key data as an array.
$data = $foreignKey->toArray();
fyre/schema 适用场景与选型建议
fyre/schema 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 467 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 01 月 16 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 fyre/schema 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 fyre/schema 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 467
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 3
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-01-16