degami / lessql
LessQL:敏捷的PHP ORM替代品
v0.4.1
2019-05-03 23:46 UTC
Requires
- php: >=5.3.4
Requires (Dev)
- codeclimate/php-test-reporter: dev-master
- friendsofphp/php-cs-fixer: v2.2.20
- phpunit/phpunit: ~4.6|~5|~6|~7
README
前往原始项目
LessQL
LessQL是一个轻量级且高效的PHP对象关系映射(ORM)替代品。
安装
使用composer安装LessQL: composer require morris/lessql
。LessQL需要PHP >= 5.3.4和PDO。
使用方法
// SCHEMA // user: id, name // post: id, title, body, date_published, is_published, user_id // categorization: category_id, post_id // category: id, title // Connection $pdo = new PDO('sqlite:blog.sqlite3'); $db = new LessQL\Database($pdo); // Find posts, their authors and categories efficiently: // Eager loading of references happens automatically. // This example only needs FOUR queries, one for each table. $posts = $db->post() ->where('is_published', 1) ->orderBy('date_published', 'DESC'); foreach ($posts as $post) { $author = $post->user()->fetch(); foreach ($post->categorizationList()->category() as $category) { // ... } } // Saving complex structures is easy $row = $db->createRow('post', array( 'title' => 'News', 'body' => 'Yay!', 'categorizationList' => array( array( 'category' => array('title' => 'New Category') ), array('category' => $existingCategoryRow) ) )); // Creates a post, a new category, two new categorizations // and connects them all correctly. $row->save();
特性
- 通过智能预加载进行高效的深度查找
- 查询数量恒定,无N+1问题
- 使用一个方法调用保存复杂的嵌套结构
- 约定优于配置
- 与数据库紧密工作:LessQL不是一个ORM
- 无需胶水代码
- 干净、易于阅读的源代码
- 已全面测试SQLite3、MySQL和PostgreSQL
- MIT许可证
主要受NotORM的启发,从头开始编写,以提供干净的API和简化的概念。