DoctrineExtensions

Custom DQL functions for Doctrine ORM across MySQL, Oracle, PostgreSQL, and SQLite

Library
Composer
vv1.5.0
2,101stars
BSD 3-Clause License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
51/100Fair
Development Activity0
Maintenance20
Community84
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
58/100Fair
Architecture65
Code Quality62
Innovation45
Learning Curve60

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 Type extension (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_LENGTH on MySQL
  • Using window functions (LAG, LEAD) for reporting-style queries against ORM entities
  • Aggregating text fields with GROUP_CONCAT/STRING_AGG per 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).

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search