Download the PHP package demos-europe/edt-dql without Composer
On this page you can find all versions of the php package demos-europe/edt-dql. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download demos-europe/edt-dql
More information about demos-europe/edt-dql
Files in demos-europe/edt-dql
Package edt-dql
Short Description Extension for demos-europe/edt-queries to use Doctrine ORM as data source.
License MIT
Informations about the package edt-dql
DoctrineQueryGenerator
Extends edt/queries
with support for Doctrine ORM.
Also functions as helper library for Doctrine ORM to generate DQL queries. Currently, the focus lies in the detection of join clauses from a given property path to sort and filter the result set.
A basic understanding of the Doctrine ORM by the user is assumed for this library to be used.
Example
Suppose we have a Book
, Person
and Address
entity.
A Book
has an author
property which references Person
entity.
A Person
has a birth
property containing information about the birth location and date.
An Birth
entity has a country
property which is a string.
The goal is to get all Book
entities of which the author was born in the USA.
This could be done by first fetching all entities from the database
and filter the result in PHP. But for performance and memory reasons
it makes sense to execute the filter in the database.
With DQL we could create a query with two joins to get the desired result:
This library can generate a similar query builder from the following code:
The main advantage of the second version does not lie in line count or readability but in the removal of the need to manually specify the query in detail. This allows dynamically receiving queries and directly executing them in the database (provided authorization and validation is checked beforehand).
Conditions
Beside the PropertyHasValue
shown above more condition types are supported.
All conditions provided by the library can be found and created using the DqlConditionFactory
class.
If the provided conditions do not suffice you can write you own clauses by implementing ClauseInterface
.
Condition Nesting
Conditions can be grouped together using AND
or OR
conjunctions:
Sorting
Defining the sorting can be done similarly as defining conditions. In the following example books will be sorted by their authors name as first priority and the authors birthdate as second priority.
If the provided sort implementations do not suffice you can write you own sort implementation.
Credits and acknowledgements
Conception and implementation by Christian Dressler with many thanks to eFrane.
All versions of edt-dql with dependencies
php Version ^8.1
demos-europe/edt-queries Version ^0.26
demos-europe/edt-paths Version ^0.26
nette/php-generator Version ^4.0
symfony/cache Version ^5 || ^6 || ^7