DoctrineExtensions
Custom DQL functions for Doctrine ORM across MySQL, Oracle, PostgreSQL, and SQLite
Repository Health
Technical Analysis
DoctrineExtensions adds dozens of database-native functions to Doctrine ORM’s query language (DQL) that aren’t available out of the box — string, date/time, math, JSON, and window functions like DATE_FORMAT, GROUP_CONCAT, JSON_CONTAINS, LAG/LEAD, and REGEXP — mapped per-driver for MySQL, Oracle, PostgreSQL, and SQLite. Each function is registered as a small class implementing Doctrine’s user-defined-function interface, so applications wire them into ORM configuration once and then use them directly in DQL or QueryBuilder expressions.
It’s a long-standing companion library for Symfony and standalone Doctrine ORM projects that need SQL capabilities DQL doesn’t expose natively, without dropping to raw SQL.
What You Get
- Per-driver DQL function classes for MySQL, Oracle, PostgreSQL, and SQLite under
src/Query/<Driver> - String, math, date/time, and JSON functions (e.g.
CONCAT_WS,REGEXP,DATE_FORMAT,JSON_CONTAINS) mapped to each database’s native syntax - Window function support (
LAG,LEAD,OVER) for MySQL - Ready-made Symfony configuration examples under
config/for registering functions declaratively - A Doctrine
Typeextension (src/Types) alongside the DQL functions
Common Use Cases
- Formatting dates or computing date differences directly in DQL instead of post-processing in PHP
- Filtering or matching with
REGEXP/LIKE-style functions across DQL queries - Querying and filtering JSON columns via
JSON_CONTAINS/JSON_LENGTHon MySQL - Using window functions (
LAG,LEAD) for reporting-style queries against ORM entities - Aggregating text fields with
GROUP_CONCAT/STRING_AGGper database
Under The Hood
Architecture - The library follows Doctrine’s user-defined-function (UDF) extension pattern: each SQL function is a standalone class under src/Query/<Driver>/ implementing DQL parsing (parse()) and SQL generation (getSql()), grouped per database driver (Mysql, Oracle, Postgresql, Sqlite) since function syntax differs across engines; a src/Types directory adds a companion Doctrine DBAL type. Tech Stack - Pure PHP 7.2+/8.x targeting Doctrine ORM 2.19-3.x, with dev dependencies on PHPUnit, PHPStan, Psalm, and PHP_CodeSniffer for static analysis and code style enforcement, plus optional Symfony cache/yaml components for the dev toolchain. Code Quality - 171 test files back the function library, and phpstan.neon/psalm.xml/phpcs.xml.dist configs show static analysis and coding-standard checks are part of the workflow, though GitHub activity has slowed (no commits since Sep 2024) even as the package remains widely depended on. API Design - Functions are registered once via ORM configuration (or Symfony’s doctrine.orm.dql.*_functions config) and then used like any native DQL function, so the integration cost is a one-time config step rather than per-query boilerplate; the per-driver split does mean function coverage varies by database (MySQL has the largest set).
Used by 2 apps in this directory
BillaBear
Ecommerce · Invoicing Finance
Self-hostable subscription management and billing platform with Stripe integration, tax automation, configurable workflows, and Twig-based document generation.
Mautic
Automation · Marketing · Ecommerce
The world's largest open source marketing automation platform — own your data, run multi-channel campaigns, and escape vendor lock-in forever.