正式 / orm
3.2.0
2024-08-20 15:12 UTC
Requires
- php: ~8.2
- formal/access-layer: ~4.0
- innmind/filesystem: ~7.4
- innmind/http-transport: ~7.2
- innmind/immutable: ~5.4
- innmind/json: ~1.3
- innmind/reflection: ~5.1
- innmind/specification: ~4.1
- innmind/time-continuum: ~3.3
- innmind/type: ~1.2
- innmind/url-template: ~3.1
- innmind/validation: ~1.4
- ramsey/uuid: ~4.7
Requires (Dev)
- innmind/black-box: ~5.1
- innmind/coding-standard: ~2.0
- innmind/operating-system: ~5.2
- vimeo/psalm: ~5.13
README
这个ORM1专注于简化数据操作。
这是通过以下方式实现的
- 使用不可变对象
- 每个聚合拥有其引用的对象
- 使用单子从Innmind生态系统(Innmind)获取聚合
- 使用规范模式来匹配聚合
这允许
- 更简单的应用程序设计(因为它可以是纯净的)
- 内存效率(ORM不会在内存中保留对象)
- 长生命周期的进程(因为没有内存泄漏)
- 异步工作
安装
composer require formal/orm
用法
use Formal\ORM\{ Manager, Sort, }; use Formal\AccessLayer\Connection\PDO; use Innmind\Url\Url; $manager = Manager::sql( PDO::of(Url::of('mysql://user:pwd@host:3306/database?charset=utf8mb4')), ); $_ = $manager ->repository(YourAggregate::class) ->all() ->sort('someProperty', Sort::asc) ->drop(150) ->take(50) ->foreach(static fn($aggregate) => doStuff($aggregate));
这个简单的示例将从数据库中检索50
个元素(从索引151
到200
),按someProperty
的升序排序,并将对每个聚合调用函数doStuff
。
注意
元素是流式的,这意味着每次只在一个聚合中保留一个对象,允许你以内存安全的方式处理长列表的元素。
文档
完整的文档可在此处找到。