强大且快速的基于PDO的数据映射器

2.0.0 2020-12-12 10:41 UTC

This package is auto-updated.

Last update: 2024-09-14 00:24:25 UTC


README

Source Code Latest Version Software License Build Status Coverage Status Quality Score

Sirius ORM是一个快速、轻量级且灵活的数据映射解决方案,旨在提高开发体验。它提供以下功能:

  1. 将行映射到您自己的实体
  2. 关系和关系聚合(COUNT/AVERAGE)
  3. 预加载 & 懒加载(不增加查询数量)
  4. 查询允许您与关系(而非表)进行JOIN
  5. 深度持久化
  6. 动态定义映射器
  7. 速度 & 低内存使用(无实体管理器)
  8. 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);

链接