2017 © Pedro Peláez
 

library mysql-doctrine-functions

MySQL Function for Doctrine : RAND(), ROUND() DATE(), DATE_FORMAT()...

image

mapado/mysql-doctrine-functions

MySQL Function for Doctrine : RAND(), ROUND() DATE(), DATE_FORMAT()...

  • Wednesday, January 11, 2017
  • by jdeniau
  • Repository
  • 13 Watchers
  • 39 Stars
  • 94,938 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 6 Forks
  • 1 Open issues
  • 8 Versions
  • 5 % Grown

The README.md

MySQL Doctrine functions

This library provides you MySQL functions for Doctrine2., (*1)

At the moment are supported, (*2)

  • RAND
  • ROUND
  • DATE
  • DATE_FORMAT

Feel free to fork and add other functions., (*3)

Installation

Get the package

With composer, (*4)

composer require mapado/mysql-doctrine-functions

Add the classes to your configuration

$config = new \Doctrine\ORM\Configuration();
$config->addCustomStringFunction('rand', \Mapado\MysqlDoctrineFunctions\DQL\MysqlRand::class);
$config->addCustomStringFunction('round', \Mapado\MysqlDoctrineFunctions\DQL\MysqlRound::class);
$config->addCustomStringFunction('date', \Mapado\MysqlDoctrineFunctions\DQL\MysqlDate::class);
$config->addCustomStringFunction('date_format', \Mapado\MysqlDoctrineFunctions\DQL\MysqlDateFormat::class);

$em = EntityManager::create($dbParams, $config);

You can of course pick just the functions you need., (*5)

Use with Symfony

If you install the library in a Symfony application, you can add this in your config.yml file (doctrine.yaml file if you use symfony flex), (*6)

# app/config/config.yml
doctrine:
    orm:
        # ...
        entity_managers:
            default:
                # ...
                dql:
                    numeric_functions:
                        rand:        'Mapado\MysqlDoctrineFunctions\DQL\MysqlRand'
                        round:       'Mapado\MysqlDoctrineFunctions\DQL\MysqlRound'
                    datetime_functions:
                        date:        'Mapado\MysqlDoctrineFunctions\DQL\MysqlDate'
                        date_format: 'Mapado\MysqlDoctrineFunctions\DQL\MysqlDateFormat'
                    # ... add all functions you need

Usage

You can now use the functions in your DQL Query, (*7)

$query = 'SELECT RAND(), ROUND(123.45) 
        FROM ...
    ';
$em->createQuery($query);

The Versions

11/01 2017

dev-master

9999999-dev

MySQL Function for Doctrine : RAND(), ROUND() DATE(), DATE_FORMAT()...

  Sources   Download

MIT

The Requires

 

function doctrine mysql mapado

15/08 2015

v1.1.3

1.1.3.0

MySQL Function for Doctrine : RAND(), ROUND() DATE(), DATE_FORMAT()...

  Sources   Download

MIT

The Requires

 

function doctrine mysql mapado

25/03 2014

v1.1.2

1.1.2.0

Provides the `RAND()` and `ROUND()` MySQL functions for Doctrine2.

  Sources   Download

MIT

The Requires

 

function doctrine mysql mapado

23/01 2014

v1.1.1

1.1.1.0

Provides the `RAND()` and `ROUND()` MySQL functions for Doctrine2.

  Sources   Download

MIT

The Requires

 

function doctrine mysql mapado

27/11 2013

v1.1.0

1.1.0.0

Provides the `RAND()` and `ROUND()` MySQL functions for Doctrine2.

  Sources   Download

MIT

The Requires

 

function doctrine mysql mapado

30/09 2013

v1.0.2

1.0.2.0

Provides the `RAND()` and `ROUND()` MySQL functions for Doctrine2.

  Sources   Download

MIT

The Requires

 

function doctrine mysql mapado

01/09 2013

v1.0.1

1.0.1.0

Provides the `RAND()` and `ROUND()` MySQL functions for Doctrine2.

  Sources   Download

MIT

The Requires

 

function doctrine mysql mapado

01/03 2013

v1.0.0

1.0.0.0

Provides the `RAND()` and `ROUND()` MySQL functions for Doctrine2.

  Sources   Download

MIT

The Requires

 

function doctrine mysql mapado