cycle / schema-builder
Cycle ORM 模式构建器
v2.9.0
2024-07-10 16:20 UTC
Requires
- php: >=8.0
- cycle/database: ^2.7.1
- cycle/orm: ^2.7
- yiisoft/friendly-exception: ^1.1
Requires (Dev)
- phpunit/phpunit: ^9.5
- spiral/tokenizer: ^2.8
- symfony/console: ^6.0 || ^7.0
- vimeo/psalm: ^5.12
- 2.x-dev
- v2.9.0
- v2.8.0
- v2.7.0
- v2.6.2
- v2.6.1
- v2.6.0
- v2.5.1
- v2.5.0
- v2.4.0
- v2.3.0
- v2.2.0
- v2.1.0
- v2.0.1
- v2.0.0
- 1.x-dev
- v1.2.1
- v1.2.0
- v1.1.23
- v1.1.22
- v1.1.21
- v1.1.20
- v1.1.19
- v1.1.18
- v1.1.17
- v1.1.16
- v1.1.15
- v1.1.4
- v1.1.3
- v1.1.2
- v1.1.1
- v1.1.0
- v1.0.11
- v1.0.10
- v1.0.9
- v1.0.8
- v1.0.7
- v1.0.6
- v1.0.5
- v1.0.4
- v1.0.3
- v1.0.2
- v1.0.1
- v1.0.0
- v0.1
This package is auto-updated.
Last update: 2024-09-10 16:53:47 UTC
README
Schema Builder 包提供了一种便捷的方式来配置你的 ORM 和数据库模式,通过 注释(属性) 或自定义生成器实现。
安装
composer require cycle/schema-builder
配置
use Cycle\Migrations; use Cycle\Database; use Cycle\Database\Config; $dbal = new Database\DatabaseManager(new Config\DatabaseConfig([ 'default' => 'default', 'databases' => [ 'default' => [ 'connection' => 'sqlite' ] ], 'connections' => [ 'sqlite' => new Config\SQLiteDriverConfig( connection: new Config\SQLite\MemoryConnectionConfig(), queryCache: true, ), ] ])); $registry = new \Cycle\Schema\Registry($dbal);
我们现在可以注册第一个实体,添加其列并链接到特定的表
use Cycle\Schema\Definition; $entity = new Definition\Entity(); $entity ->setRole('user') ->setClass(User::class); // add fields $entity->getFields() ->set('id', (new Definition\Field())->setType('primary')->setColumn('id')->setPrimary(true)) ->set('name', (new Definition\Field())->setType('string(32)')->setColumn('user_name')); // register entity $r->register($entity); // associate table $r->linkTable($entity, 'default', 'users');
你可以使用 Cycle\Schema\Compiler
立即生成 ORM 模式
use Cycle\Schema\Compiler; $schema = (new Compiler())->compile($r); $orm = $orm->with(schema: new \Cycle\ORM\Schema($schema));
有关 Schema builder 包的更多信息,请在此处。
许可证
MIT 许可证(MIT)。有关更多信息,请参阅 LICENSE
。由 Spiral Scout 维护。