PHPackages                             demos-europe/edt-dql - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. demos-europe/edt-dql

ActiveLibrary

demos-europe/edt-dql
====================

Extension for demos-europe/edt-queries to use Doctrine ORM as data source.

0.26.0(1y ago)221.8k↓21.4%1MITPHPPHP ^8.1

Since Jun 23Pushed 1y ago1 watchersCompare

[ Source](https://github.com/demos-europe/edt-dql)[ Packagist](https://packagist.org/packages/demos-europe/edt-dql)[ RSS](/packages/demos-europe-edt-dql/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (5)Versions (110)Used By (1)

DoctrineQueryGenerator
======================

[](#doctrinequerygenerator)

Extends `edt/queries` with support for Doctrine ORM.

Also functions as helper library for [Doctrine ORM](https://www.doctrine-project.org/projects/orm.html) to generate [DQL](https://www.doctrine-project.org/projects/doctrine-orm/en/2.7/reference/dql-doctrine-query-language.html)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
-------

[](#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:

```
use \Tests\data\DqlModel\Book;
$queryBuilder = $this->getEntityManager()->createQueryBuilder()
    ->select('Book')
    ->from(Book::class, 'Book')
    ->leftJoin('Book.author', 'Person')
    ->leftJoin('Person.birth', 'Birth')
    ->where('Birth.country = :countryName')
    ->setParameter('countryName', 'USA');
```

This library can generate a similar query builder from the following code:

```
use \Tests\data\DqlModel\Book;
use EDT\DqlQuerying\ConditionFactories\DqlConditionFactory;
use \EDT\DqlQuerying\Utilities\QueryBuilderPreparer;
/** @var \Doctrine\ORM\EntityManager $entityManager */
$entityManager = $this->getEntityManager();
$conditionFactory = new DqlConditionFactory();
$metadataFactory = $entityManager->getMetadataFactory();

$builderPreparer = new QueryBuilderPreparer(Book::class, $metadataFactory, new JoinFinder($metadataFactory));
$builderPreparer->setWhereExpressions([
    $conditionFactory->propertyHasValue('USA', 'authors', 'birth', 'country'),
]);

$builderPreparer->fillQueryBuilder($entityManager->createQueryBuilder());
```

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
----------

[](#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](writing_dql_clauses.md) by implementing `ClauseInterface`.

### Condition Nesting

[](#condition-nesting)

Conditions can be grouped together using `AND` or `OR` conjunctions:

```
$conditionFactory = new EDT\DqlQuerying\ConditionFactories\DqlConditionFactory();
$andConditions = [ /* ... */];
$orConditions = [ /* ... */];
$orCondition = $conditionFactory->anyConditionApplies(...$orConditions);
$nestedCondition = $conditionFactory->allConditionsApply(...$andConditions);
```

Sorting
-------

[](#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.

```
use EDT\DqlQuerying\ConditionFactories\DqlConditionFactory;
use EDT\DqlQuerying\SortMethodFactories\SortMethodFactory;
use \Tests\data\DqlModel\Book;
use EDT\DqlQuerying\Utilities\QueryBuilderPreparer;
/** @var \Doctrine\ORM\EntityManager $entityManager */
$entityManager = $this->getEntityManager();
$conditionFactory = new DqlConditionFactory();
$sortingFactory = new SortMethodFactory();
$metadataFactory = $entityManager->getMetadataFactory();

$builderPreparer = new QueryBuilderPreparer(Book::class, $metadataFactory, new JoinFinder($metadataFactory));
$builderPreparer->setSelectExpressions([
    $sortingFactory->propertyAscending('authors', 'name'),
    $sortingFactory->propertyDescending('authors', 'birthdate'),
]);

$builderPreparer->fillQueryBuilder($entityManager->createQueryBuilder());
```

If the provided sort implementations do not suffice you can [write you own sort implementation](writing_dql_clauses.md#OrderByInterface).

Credits and acknowledgements
----------------------------

[](#credits-and-acknowledgements)

Conception and implementation by Christian Dressler with many thanks to [eFrane](https://github.com/eFrane).

###  Health Score

40

—

FairBetter than 88% of packages

Maintenance41

Moderate activity, may be stable

Popularity30

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 99.6% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~9 days

Recently: every ~116 days

Total

109

Last Release

386d ago

PHP version history (5 changes)0.6.1PHP &gt;=7.3,&lt;8.2

0.8.0PHP &gt;=7.3,&lt;8

0.13.0PHP &gt;=7.4,&lt;8

0.14.1PHP ^7.4 || ^8.0

0.17.5PHP ^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/b2998f0a3cfbccb2c469bde14aa00b8f61fb12380a7785213927cbaf033e4f12?d=identicon)[demosci](/maintainers/demosci)

---

Top Contributors

[![actions-user](https://avatars.githubusercontent.com/u/65916846?v=4)](https://github.com/actions-user "actions-user (284 commits)")[![graupnerdemos](https://avatars.githubusercontent.com/u/40465804?v=4)](https://github.com/graupnerdemos "graupnerdemos (1 commits)")

### Embed Badge

![Health badge](/badges/demos-europe-edt-dql/health.svg)

```
[![Health](https://phpackages.com/badges/demos-europe-edt-dql/health.svg)](https://phpackages.com/packages/demos-europe-edt-dql)
```

###  Alternatives

[easycorp/easyadmin-bundle

Admin generator for Symfony applications

4.3k16.7M310](/packages/easycorp-easyadmin-bundle)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M152](/packages/sulu-sulu)[prestashop/prestashop

PrestaShop is an Open Source e-commerce platform, committed to providing the best shopping cart experience for both merchants and customers.

9.0k15.4k](/packages/prestashop-prestashop)[tempest/framework

The PHP framework that gets out of your way.

2.1k23.1k9](/packages/tempest-framework)[ec-cube/ec-cube

EC-CUBE EC open platform.

78527.0k1](/packages/ec-cube-ec-cube)[bacula-web/bacula-web

The open source web based reporting and monitoring tool for Bacula

1537.5k](/packages/bacula-web-bacula-web)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
