dukecity/doctrineextensions

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

v2.0.2 2023-11-07 18:59 UTC

README

Build Status Build Status codecov 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 2023 becomes strftime('%m %d %Y', field) -> 01 01 2023.

Installation

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

composer require dukecity/doctrineextensions

Usage

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.

If you are using DoctrineExtensions standalone, you might want to fire up the autoloader:

<?php

$classLoader = new \Doctrine\Common\ClassLoader('DoctrineExtensions', '/path/to/extensions');
$classLoader->register();

For more information check out the documentation of Doctrine DQL User Defined Functions.

Motivation

The original repo is not so good maintained anymore. The motivation for this Repo, is to

  • add more functions
  • improve CodeCoverage and testing (your help is welcome)
  • modernize

Credits

Credits and thanks to the original repo and their maintainers. https://github.com/beberlei/DoctrineExtensions

Test and Contributing

If you want to run phpunit:

composer run test

If you want to run php-cs-fixer:

composer run lint

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.