los / uql
PHP library to transform url query into db partial queries
Fund package maintenance!
Lansoweb
Installs: 29 905
Dependents: 2
Suggesters: 0
Security: 0
Stars: 4
Watchers: 3
Forks: 2
Open Issues: 0
Requires
- php: ^8.1
- psr/http-message: ^1.0 || ^2.0
Requires (Dev)
- doctrine/coding-standard: ^12.0
- laminas/laminas-db: ^2.9
- laminas/laminas-diactoros: ^3.2
- php-coveralls/php-coveralls: ^2.6
- phpstan/phpstan: ^1.10
- phpunit/phpunit: ^10.3
- squizlabs/php_codesniffer: ^3.7
README
This library utilizes url query parameters and generates db queries.
At this moment, it provides integration with:
Planned:
Installing
composer require los/uql
Usage
The builder uses the query parameters 'q' for the queries and 'h' for hint (sort, order, limits, etc). You can change these in the constructor:
$builder = new ZendDbBuilder($select, 'query', 'hint');
The Select instance returned by the builder methods is a clone from the one passed in the constructor.
Zend DB
Passing the request directly:
public function handle(ServerRequestInterface $request): ResponseInterface { $select = new \Laminas\Db\Select('table'); $select = (new ZendDbBuilder($select))->fromRequest($request); $statement = $sql->prepareStatementForSqlObject($select); $results = $statement->execute(); }
or manually passing the parameters:
public function handle(ServerRequestInterface $request): ResponseInterface { $queryParams = $request->getQueryParams(); $query = $queryParams['q'] ?? []; $hint = $queryParams['h'] ?? []; $select = new \Laminas\Db\Select('table'); $select = (new ZendDbBuilder($select))->fromParams($query, $hint); $statement = $sql->prepareStatementForSqlObject($select); $results = $statement->execute(); }
Examples:
You can mix and nest queries: