Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/adnanmula/criteria
https://github.com/adnanmula/criteria
Last synced: 7 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/adnanmula/criteria
- Owner: adnanmula
- Created: 2023-01-11T22:39:36.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2024-02-25T08:04:05.000Z (9 months ago)
- Last Synced: 2024-04-25T16:03:17.283Z (7 months ago)
- Language: PHP
- Size: 24.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# Criteria
Useful classes to build dynamic queries, made for postgres.
## Installation
Install via [composer](https://getcomposer.org/)
```shell
composer require adnanmula/criteria
```## Usage
```php
//Use the criteria class to build queries$criteria = new Criteria(
10, //Offset
20, //Limit
new Sorting(
new Order(
new FilterField('name'),
OrderType::ASC,
),
new Order(
new FilterField('name'),
OrderType::DESC,
),
),
new AndFilterGroup(
FilterType::OR,
new Filter(new FilterField('id'), new StringFilterValue('id'), FilterOperator::EQUAL),
new Filter(new FilterField('field'), new StringArrayFilterValue('value1', 'value2', 'value3'), FilterOperator::IN),
...$moreFilters
),
new OrFilterGroup(
FilterType::AND,
new Filter(new FilterField('json_field'), new ArrayElementFilterValue('value'), FilterOperator::IN_ARRAY),
new Filter(new FilterField('amount'), new IntFilterValue(3), FilterOperator::LESS_OR_EQUAL),
),
...$moreFilterGroups,
);
``````php
//Example of repository$query = $this->connection->createQueryBuilder()->select('a.fields')
->from('table', 'a');(new DbalCriteriaAdapter($builder))->execute($criteria);
$result = $query->execute()->fetchAllAssociative();
```