plasma/schemas
Composer 安装命令:
composer require plasma/schemas
包简介
Schemas map any data source into a PHP object.
README 文档
README
Schemas is a simple Object Relational Mapper (ORM) for Plasma. Schemas maps any data source into a PHP object.
Getting Started
Schemas can be installed through composer.
composer require plasma/schemas
You first need to create a Plasma client and then create a Repository (which acts like a client) with the created client.
Then you need to create your schema classes and the directory for these schema classes. You will need to register these directories to the Repository.
Directories build schemas from query results and interface with the repository for queries.
After that, each call onto the Repository query or execute methods will give you a dedicated SchemaCollection with the Schema instances.
A call to Repository::prepare will give you, if successful, a wrapped Statement instance. The wrapper has the same purpose as the Repository.
$loop = \React\EventLoop\Factory::create(); $factory = new \Plasma\Drivers\MySQL\DriverFactory($loop, array()); $client = \Plasma\Client::create($factory, 'root:1234@localhost'); $repository = new \Plasma\Schemas\Repository($client); /** * Our example table "users" consists of two columns: * - id ; auto incremented integer (length 12) primary * - name ; varchar(255) utf8mb4_generl_ci */ class Users extends \Plasma\Schemas\AbstractSchema { public $id; public $name; /** * Returns the schema definition. * @return \Plasma\Schemas\ColumnDefinitionInterface[] */ static function getDefinition(): array { return array( // A generic column definition builder // solely for ease of use and does not // have to be used. // Any Plasma Column Definition // can be used. static::getColDefBuilder() ->name('id') ->type('INTEGER') ->length(12) ->autoIncrement() ->primary() ->getDefinition(), static::getColDefBuilder() ->name('name') ->type('VARCHAR') ->length(255) ->getDefinition() ); } /** * Returns the name of the table. * @return string */ static function getTableName(): string { return 'users'; } /** * Returns the name of the identifier column (primary or unique), or null. * @return string|null */ static function getIdentifierColumn(): ?string { return 'id'; } } // null is the SQL grammar (see plasma/sql-common) $builderA = new \Plasma\Schemas\SQLDirectory(Users::class, null); $repository->registerDirectory('users', $builderA); $repository->execute('SELECT * FROM `users`', array()) ->done(function (\Plasma\Schemas\SchemaCollection $collection) { // Do something with the collection }); $loop->run();
Preloads
Schemas has a mechanism called Preloads.
Preloads are a way to load foreign references at the same time as a schema gets loaded, and let your schema be always filled with the foreign reference schema. How the preloads are exactly loaded depends on the Directory implementation.
Preloads are foreign targets with fetch mode ALWAYS and are automatically handled.
Foreign target with fetch mode LAZY are not automatically loaded and need to be explicitely asked for by calling resolveForeignTargets on the schema.
Whether one uses one over the other fetch mode depends on the use case. It makes sense to only preload schemas you actually really always need.
Preloads are supported through the ColumnDefinitionInterface. Current implementations are the ColumnDefinition implementation and the ColumnDefinitionBuilder.
Documentation
plasma/schemas 适用场景与选型建议
plasma/schemas 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 276 次下载、GitHub Stars 达 2, 最近一次更新时间为 2019 年 01 月 19 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 plasma/schemas 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 plasma/schemas 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 276
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2019-01-19