beberlei/doctrineextensions

A set of extensions to Doctrine 2 that add support for additional query functions available in MySQL, Oracle, PostgreSQL and SQLite.

Installs: 55 776 127

Dependents: 165

Suggesters: 11

Security: 0

Stars: 2 044

Watchers: 55

Forks: 432

v1.5.0 2024-03-03 17:55 UTC

README

Build Status Build Status Packagist Packagist Packagist Packagist

A set of extensions to Doctrine 2 that add support for functions available in MySQL, Oracle, PostgreSQL and SQLite.

Note: SQLite date functions are implemented as strftime(format, value). SQLite only supports the most common formats, so date_format will convert the mysql substitutions to the closest available SQLite substitutions. This means date_format(field, '%b %D %Y') -> Jan 1st 2015 becomes strftime('%m %d %Y', field) -> 01 01 2015.

Installation

To install this library, run the command below and you will get the latest version:

composer require beberlei/doctrineextensions

If you want to run phpunit:

composer run test

If you want to run php-cs-fixer:

composer run lint

Usage

Symfony

If you are using DoctrineExtensions with Symfony read How to Register custom DQL Functions.

You can find example Symfony configuration for using DoctrineExtensions custom DQL functions in config.

Standalone

If you are using DoctrineExtensions standalone, you need to register the custom function in the ORM configuration. For more information check out the documentation of Doctrine DQL User Defined Functions.

Notes

  • MySQL DATE_ADD is available in DQL as DATEADD(CURRENT_DATE(), 1, 'DAY')
  • MySQL DATE_SUB is available in DQL as DATESUB(CURRENT_DATE(), 1, 'DAY')
  • MySQL IF is available in DQL as IFELSE(field > 0, 'true', 'false')

Troubleshooting

Issues are disabled on this repository, if a custom DQL function that you want isn't provided, or does not support the arguments you want to pass, pull requests are open and we would love to have your contributions.