Skip to content

avkluchko/postgres-doctrine-extensions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Postgres Doctrine Extensions

Build Status Total Downloads Latest Stable Version License

Doctrine extensions for working with PostgreSQL database

Requirements

Installation

composer require avkluchko/postgres-doctrine-extensions

Add the necessary extensions in the doctrine.yaml:

doctrine:
    orm:
        dql:
            string_functions:
                cast: AVKluchko\PostgresDoctrineExtensions\DQL\Cast
                date_part: AVKluchko\PostgresDoctrineExtensions\DQL\DatePart
                make_date: AVKluchko\PostgresDoctrineExtensions\DQL\MakeDate
                to_char: AVKluchko\PostgresDoctrineExtensions\DQL\ToChar

Usage

// src/Filters/SomeFilter.php
public class SomeFilter
{
    // ...
    protected function createCondition(string $year, string $field, string $operator, string $parameterName): string
    {
        return sprintf(
            'make_date(%s, cast(date_part(\'month\', %s) as integer), cast(date_part(\'day\', %s) as integer)) %s :%s',
            $year,
            $field,
            $field,
            $operator,
            $parameterName
        );
    }
}