siriusphp / sql
适用于PDO连接的灵活查询构建库,具有小型API界面和自动完成支持(认知负荷低)。需要atlas/pdo连接。
1.2.1
2020-11-24 15:03 UTC
Requires
- php: >=7.1
- atlas/pdo: ^1.1
Requires (Dev)
- mockery/mockery: ^1.3
- phpunit/phpunit: ^8.5
This package is auto-updated.
Last update: 2024-08-24 22:57:24 UTC
README
siriusphp/sql
库旨在帮助您以快速和安全的方式构建和执行SQL简单和复杂查询。
如以下示例所示,词汇尽可能接近SQL
use Atlas\Pdo\Connection; use Sirius\Sql\Select; use Sirius\Sql\ConditionsEnum; $connection = Connection::new('sqlite::memory:'); $select = new Select($connection); // find the 10 "cool" posts that are published and also retrieve the comments count $select->distinct() ->columns('posts.*', 'COUNT(comments.id) AS comments_count') ->from('posts') ->join('LEFT', 'comments', 'comments.commentable_id = posts.id AND comments.commentable_type = %s', 'posts') ->where('posts.published_at < NOW()') ->where('posts.title', 'cool', ConditionsEnum::CONTAINS) ->groupBy('posts.id') ->limit(10); $posts = $select->fectchAll();
链接
致谢
这个库是atlas/query的衍生作品。我创建这个库有两个原因
- 通过删除一些方法并实现其他方法来实现相同的目标(例如:嵌套条件)来降低认知负荷
- 针对最常见的情况优化一些操作(例如:
where($column, $str, 'does_not_contain')
与where($column . ' LIKE ', '%' . $str . '%')
)