glooby / doctrine-query-builder
非常强大的查询构建器,非常适合API
0.1.2
2018-03-20 18:44 UTC
Requires
- php: >=5.6
- doctrine/orm: ^2.5
- symfony/framework-bundle: ^3.2
This package is auto-updated.
Last update: 2024-09-14 03:35:56 UTC
README
非常强大的查询构建器,非常适合构建API或需要构建非常灵活的查询时使用
支持无限嵌套的AND/OR组,大多数常见的SQL运算符,连接,排序,distinct等
要求
- PHP >= 5.6
- Symfony HTTP Foundation > 3.2
- Doctrine ORM > 2.5
安装
使用 Composer
{ "require": { "glooby/doctrine-query-builder": "dev-master" } }
用法
use \Glooby\Doctrine\QueryBuilder\QueryBuilder; $repo = $this->getDoctrine()->getManager()->getRepository('AcmeMainBundle:Person'); $qb = new QueryBuilder(); $results = $qb->build($repo, $data)->getQuery()->getResult(); return new JsonResponse($results);
示例数据
{ "alias": "p", "select": ["p.id"], "where": { "$or": { "p.city": { "$same": "c.city" }, "p.zipCode": { "$same": "c.zipCode" }, "p.street": { "$same": "c.street" }, }, "c.city": { "$in": [ "New York", "London" ] }, "c.employees": { "$equals": 1 }, "l.code": 49, "p.country": "$not_null", "p.phone": "$is_null", "c.assets": { "$gte": 1000 }, "c.turnover": { "$lt": 10000 }, "t.code": { "$in": [1, 2, 3] }, "r.title": { "$not_in": ":titles" } }, "distinct": true, "params": { "titles": ["CFO", "CMO"] }, "orderBy": { "p.name": "asc" }, "join": { "p.roles": "r", "r.company": "c", "c.trades": { "alias": "t", "type": "left" } } }