https://github.com/kilhage/doctrine-query-builder
Powerful query builder, perfect for apis
https://github.com/kilhage/doctrine-query-builder
doctrine sql symfony
Last synced: 9 days ago
JSON representation
Powerful query builder, perfect for apis
- Host: GitHub
- URL: https://github.com/kilhage/doctrine-query-builder
- Owner: kilhage
- License: mit
- Created: 2017-03-20T20:26:37.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2021-05-13T20:30:52.000Z (almost 5 years ago)
- Last Synced: 2025-12-14T08:17:40.041Z (4 months ago)
- Topics: doctrine, sql, symfony
- Language: PHP
- Homepage:
- Size: 800 KB
- Stars: 2
- Watchers: 1
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# doctrine-query-builder
Very powerful query builder, perfect to use when building api's or have the need to build very flexible queries
Supports unlimited nested AND/OR groups, most of the common SQL operators, joins, order by, distinct etc
### Requirements:
- PHP >= 5.6
- Symfony HTTP Foundation > 3.2
- Doctrine ORM > 2.5
### Installation:
With [Composer](https://getcomposer.org/):
```json
{
"require": {
"glooby/doctrine-query-builder": "dev-master"
}
}
```
### Usage:
```php
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);
```
### Example data:
```json
{
"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"
}
}
}
```