siriusphp / orm
强大且快速的基于PDO的数据映射器
2.0.0
2020-12-12 10:41 UTC
Requires
- php: >=7.2
- ext-json: *
- atlas/pdo: ^1.1
- doctrine/collections: ^1.6
- psr/event-dispatcher: 1.0
- siriusphp/sql: ^1.2
- symfony/inflector: ^4.4
Requires (Dev)
- doctrine/dbal: ^2.10
- league/event: ^3.0
- mockery/mockery: ^1.3
- nette/php-generator: ^3.4
- phpunit/phpunit: ^8.5
Suggests
- league/event: For event dispatching
This package is auto-updated.
Last update: 2024-09-14 00:24:25 UTC
README
Sirius ORM是一个快速、轻量级且灵活的数据映射解决方案,旨在提高开发体验。它提供以下功能:
- 将行映射到您自己的实体
- 关系和关系聚合(COUNT/AVERAGE)
- 预加载 & 懒加载(不增加查询数量)
- 查询允许您与关系(而非表)进行JOIN
- 深度持久化
- 动态定义映射器
- 速度 & 低内存使用(无实体管理器)
- 90%以上的代码覆盖率
安装
composer require siriusphp/orm
初始化
use Sirius\Orm\Orm; use Sirius\Orm\ConnectionLocator; $connectionLocator = ConnectionLocator::new( 'mysql:host=localhost;dbname=testdb', 'username', 'password' ); $orm = new Orm($connectionLocator);
配置
即,注册映射器和关系
$orm->register('pages', MapperConfig::fromArray([ /** * here goes the configuration */ ])); // continue with the rest of mappers
使用方法
// find by ID $page = $orm->find('pages', 1); // or via the mapper $page = $orm->get('pages')->find(1); // query $pages = $orm->select('pages') ->where('status', 'published') ->orderBy('date desc') ->limit(10) ->get(); // manipulate $page->title = 'Best ORM evah!'; $page->featured_image->path = 'orm_schema.png'; // persist $orm->save($page); // or via the mapper $orm->get('pages')->save($page);