PostgreSQL enhancements for Doctrine

Overview

Scrutinizer Code Quality Build Status Coverage Status Latest Stable Version Total Downloads

What's this?

This package provides Doctrine support for some specific PostgreSQL 9.4+ features:

  • Support of JSONB and some array data-types (at present integers, BOOL, TEXT and JSONB)
  • Implementation of the most commonly used functions and operators when working with array and JSON data-types
  • Functions for text search
  • Aggregate functions

It can be integrated in a simple manner with Symfony, Laravel and other frameworks that make use of Doctrine.

You can easily extend package's behaviour with your own array-like data-types or other desired functions. Read more about this in the contributing guide.


What is available?

Full set of the available types can be found here.

Full set of the available functions and extra operators can be found here.


How to install?

Easiest and recommended way is with Composer

composer require martin-georgiev/postgresql-for-doctrine

How to integrate with your framework?

Read the guide with examples for Symfony.

Read the guide with examples for Laravel.

Read the guide with examples for Doctrine.


Check for common use-cases, examples and known errors.


License

This package is licensed under the MIT License.

Comments
  • Adding ILIKE support

    Adding ILIKE support

    Hello Martin,

    I use your package in my project, and I want to say BIG thanks for your work. Your package is really helpful.

    And I want to suggest to you to add ILIKE function support. I can do it by myself, but it would be great if you will help me with understanding what is inside your package.

    feature request 
    opened by llaakkkk 11
  • Can't use this package with PHP 7.4

    Can't use this package with PHP 7.4

    $ composer require martin-georgiev/postgresql-for-doctrine
    
    Using version ^1.5 for martin-georgiev/postgresql-for-doctrine
    ...
    
    Your requirements could not be resolved to an installable set of packages.
    
      Problem 1
        - Root composer.json requires php ^8.0 but your php version (7.4.12) does not satisfy that requirement.
    

    I see that in your composer.json is specified:

    "php": "^7.2|^8.0",
    

    I think there should be a double pipe. Proof. And the same on stackoverflow, see the comment there.

    opened by VijitCoder 9
  • problem with null

    problem with null

    this line would be a problem with array entries that are null, which is valid for the postgres arrays

    https://github.com/martin-georgiev/postgresql-for-doctrine/blob/6267c5693218e3ac1d0cecb6ff65ecb6e279ea78/src/MartinGeorgiev/Doctrine/DBAL/Types/SmallIntArray.php#L32

    bug 
    opened by gareth-ib 8
  • Help with setup

    Help with setup

    Hello!

    First off I want to say this package looks really awesome. I am trying out postgres for the first time because I want to be able to store and query json for a particular use case I have... However I'm having some issues figuring out how to actually use the tools provided in this package. A few examples would be really great, though I am grateful for your time putting the package together either way.

    Thanks again!

    help wanted question 
    opened by isaackearl 8
  • Example for JsonGetFieldAsText

    Example for JsonGetFieldAsText

    Hi,

    Could you please give me an example in Doctrine for this SQL query :

    SELECT id, title
    FROM my_table
    where title->>'fr' like '%AAA%';
    

    I've tried some syntaxe in DQL, but i don't find a way to use it.

    help wanted 
    opened by steevanb 7
  • Cast field to json and introduce JsonbGetFieldAsText function

    Cast field to json and introduce JsonbGetFieldAsText function

    Add possibility to cast any column to json (or jsonb) and get field as text

    Also I've fixed table intends Closes https://github.com/martin-georgiev/postgresql-for-doctrine/issues/113

    opened by dmitryuk 6
  • Bug: stored JSON value may be integer/float/string

    Bug: stored JSON value may be integer/float/string

    We are storing variable type of data in JSONB field. It can be object, integer, float or string. So we have an issue with Jsonb and primitive types. I think array type must be removed from these methods.

    https://github.com/martin-georgiev/postgresql-for-doctrine/blob/master/src/MartinGeorgiev/Doctrine/DBAL/Types/Jsonb.php#L45 https://github.com/martin-georgiev/postgresql-for-doctrine/blob/master/src/MartinGeorgiev/Doctrine/DBAL/Types/JsonTransformer.php#L33

    enhancement 
    opened by strider2038 5
  • Made it possible for the TO_* functions to take more varied arguments

    Made it possible for the TO_* functions to take more varied arguments

    We want to be able to pass any kind of StringPrimary into the TO_JSONB function, however, I think it makes sense to be able to pass e.g. a SimpleArithmeticExpression as well, and it seems NewValue is the best corresponding type for that.

    Also, even though we're only using it in TO_JSONB, obviously this makes sense for the other TO_* functions too.

    enhancement 
    opened by magnusnordlander 5
  • Add support overlaps for date intervals

    Add support overlaps for date intervals

    Hi. I'm using your good library, but notice lack of date functions. So I added implementation for one of the most useful functions "OVERLAPS".

    https://www.postgresql.org/docs/9.6/functions-datetime.html

    opened by gallyamow 4
  • Wanted to add your package in PHP 8.0.12 project, but PHP version requirement is not met

    Wanted to add your package in PHP 8.0.12 project, but PHP version requirement is not met

    I wanted to use your package in a project using PHP version 8.0.12.

    Your package needs at least PHP 7.2 so I thought it would work, but composer stops the process and give me this :

    Problem 1 - martin-georgiev/postgresql-for-doctrine v1.5.0 requires php ^7.2 -> your php version (8.0.12) does not satisfy that requirement. - martin-georgiev/postgresql-for-doctrine[v1.5.1, ..., v1.5.2] require doctrine/dbal ~2.5 -> found doctrine/dbal[v2.5.0, ..., 2.13.4] but the package is fixed to 3.1.3 (lock file version) by a partial update and that version does not match. Make sure you list it as an argument for the update command. - Root composer.json requires martin-georgiev/postgresql-for-doctrine ^1.5 -> satisfiable by martin-georgiev/postgresql-for-doctrine[v1.5.0, v1.5.1, v1.5.2].

    Do you know why does the PHP requirements are not me ?

    Thanks for letting me know, and fix bug if it is one

    opened by TaamKaGG 4
  • Fix deprecations

    Fix deprecations

    • Add requiresSQLCommentHint() to BaseType

    See doctrine/DoctrineBundle#947 Fixes #50

    • Drop null parameter on call to TestCase->setMethods()

    The method is type hinted to array so null is throwing a type error

    opened by GwendolenLynch 4
  • float[] type

    float[] type

    Not really an issue, but a suggestion, I've implemented FloatArray locally for a project:

    class FloatArray extends BaseArray
    {
        protected const TYPE_NAME = 'float[]';
    
        /**
         * @param mixed $item
         */
        public function isValidArrayItemForDatabase($item): bool
        {
            return (\is_float($item) || \is_int($item) || \is_string($item))
                && preg_match('/^-?[0-9]+(?:\.[0-9]+)?$/', (string) $item);
        }
    
        /**
         * @param float|int|string|null $item Whole number
         */
        public function transformArrayItemForPHP($item): ?float
        {
            if (null === $item) {
                return null;
            }
    
            $isInvalidPHPInt = false === preg_match('/^-?[0-9]+(?:\.[0-9]+)?$/', (string) $item);
            if ($isInvalidPHPInt) {
                throw new ConversionException(sprintf('Given value of %s content cannot be transformed to valid PHP float.', var_export($item, true)));
            }
    
            return (float) $item;
        }
    }
    

    In that case, I do not verify the number of digits (https://www.postgresql.org/docs/current/datatype-numeric.html) depending on real (float4) or double precision (float8). Doctrine natively not handle float4 (real) but only floa8(double precision), PHP have a precision of 14 digits. That's why I do not do the check (but in external library like here, seem important to do, if the user change the precision to 16 for exemple).

    Name | Storage Size | Description | Range -- | -- | -- | -- real | 4 bytes | variable-precision, inexact | 6 decimal digits precision double precision | 8 bytes | variable-precision, inexact | 15 decimal digits precision

    It seems there also have a min/max value like done with Integer array:

    On most platforms, the real type has a range of at least 1E-37 to 1E+37 with a precision of at least 6 decimal digits. The double precision type typically has a range of around 1E-307 to 1E+308 with a precision of at least 15 digits. Values that are too large or too small will cause an error. Rounding might take place if the precision of an input number is too high. Numbers too close to zero that are not representable as distinct from zero will cause an underflow error.

    1. Check the min/max is not really difficult I think, do the same like done with IntegerArray
    2. Check the number of digits seen a more little difficult: convert to string, count number chars after the ".", and if scientific notation use the "E" ?
    opened by mpiot 0
  • array_agg doesn't support ORDER BY

    array_agg doesn't support ORDER BY

    When I use the function like this array_agg(d.startDate ORDER BY d.startDate DESC), I get en error "[Syntax Error] line 0, col 64: Error: Expected Doctrine\ORM\Query\Lexer::T_CLOSE_PARENTHESIS, got 'ORDER'" Please fix it.

    opened by olek07 0
  • Postgres 14-specific JSON syntax

    Postgres 14-specific JSON syntax

    In reviewing the documentation for Postgres 14, I saw this:

    PostgreSQL has supported manipulating JSON data since the release of PostgreSQL 9.2, though retrieval of values used a unique syntax. PostgreSQL 14 now lets you access JSON data using subscripts, e.g. a query like SELECT ('{ "postgres": { "release": 14 }}'::jsonb)['postgres']['release']; now works. This aligns PostgreSQL with syntax that is commonly recognized for retrieving information from JSON data. The subscripting framework added to PostgreSQL 14 can be generally extended to other nested data structures, and is also applied to the hstore data type in this release.

    Range types, also first released in PostgreSQL 9.2, now have support for noncontiguous ranges through the introduction of the "multirange" data type. A multirange is an ordered list of ranges that are nonoverlapping, which lets developers write simpler queries for dealing with complex sequences of ranges. The range types native to PostgreSQL (dates, times, numbers) support multiranges, and other data types can be extended to use multirange support.

    Are there parts of this bundle that alter the query syntax based on version? This is probably a minor enhancement that would only be relevant for debugging, but I'm curious if there's any benefit, beyond the syntax change, to leveraging this new feature from postgres 14.

    enhancement 
    opened by tacman 1
  • How to use TO_JSON with JSON_GET_FIELD_AS_TEXT

    How to use TO_JSON with JSON_GET_FIELD_AS_TEXT

    I want to get sql like select (np.params::json)->> 'slug', np.params is a text field

    DDL:

    JSON_GET_FIELD_AS_TEXT(TO_JSON(np.params), 'slug')
    

    Finally got an error: Doctrine\ORM\Query\QueryException: [Syntax Error] line 0, col 110: Error: Expected Doctrine\ORM\Query\Lexer::T_INPUT_PARAMETER, got 'np' What I do wrong?

    opened by dmitryuk 0
  • ARRAY with multiple arguments

    ARRAY with multiple arguments

    I'd like to use this kind of postgres code Array_to_string(ARRAY['a', 'b', 'c'], ';') which gives a;b;c

    but this does not parse in dql :

    ARRAY_TO_STRING( ARRAY( 'a', 'b', 'c' ), ';')
    -> [Syntax Error] line 0, col 70: Error: Expected Doctrine\ORM\Query\Lexer::T_CLOSE_PARENTHESIS, got ','
    
    opened by flaushi 2
Releases(v2.0.1)
  • v2.0.1(Dec 29, 2022)

    What's Changed

    • Address regression with support of bool values in JSONB by @martin-georgiev in https://github.com/martin-georgiev/postgresql-for-doctrine/pull/131

    Full Changelog: https://github.com/martin-georgiev/postgresql-for-doctrine/compare/v2.0.0...v2.0.1

    Source code(tar.gz)
    Source code(zip)
  • v2.0.0(Dec 26, 2022)

    What's Changed

    New features


    • Add support for CAST by @mpiot in https://github.com/martin-georgiev/postgresql-for-doctrine/pull/116
    • Add support for JSONB_SET_LAX by @martin-georgiev in https://github.com/martin-georgiev/postgresql-for-doctrine/pull/125
    • Add support for JSONB_PRETTY by @martin-georgiev in https://github.com/martin-georgiev/postgresql-for-doctrine/pull/126
    • Add support for REGEXP_LIKE and REGEXP_MATCH and their flagged variations by @martin-georgiev in https://github.com/martin-georgiev/postgresql-for-doctrine/pull/128

    BC changes


    • Drop support for PHP 7 by @martin-georgiev in https://github.com/martin-georgiev/postgresql-for-doctrine/pull/121
    • Promote docBlock annotations to native property, argument and return types by @martin-georgiev in https://github.com/martin-georgiev/postgresql-for-doctrine/pull/127

    Housekeeping


    • Tweak Deptrac configuration by @martin-georgiev in https://github.com/martin-georgiev/postgresql-for-doctrine/pull/123
    • Enable more Rector setlists by @martin-georgiev in https://github.com/martin-georgiev/postgresql-for-doctrine/pull/124

    Full Changelog: https://github.com/martin-georgiev/postgresql-for-doctrine/compare/v1.8.0...v2.0.0

    Source code(tar.gz)
    Source code(zip)
  • v1.8.0(Aug 29, 2022)

    What's Changed

    • Add support for regex operators by @jenkoian in https://github.com/martin-georgiev/postgresql-for-doctrine/pull/106
    • Update dev dependencies by @martin-georgiev in https://github.com/martin-georgiev/postgresql-for-doctrine/pull/110
    • Migrate from Travis to GitHub Actions by @martin-georgiev in https://github.com/martin-georgiev/postgresql-for-doctrine/pull/109
    • Exclude from the git archive any security checker executables by @martin-georgiev in https://github.com/martin-georgiev/postgresql-for-doctrine/pull/108
    • Fix broken CI due to newest version of PHPStan by @martin-georgiev in https://github.com/martin-georgiev/postgresql-for-doctrine/pull/117
    • Update qossmic/deptrac-shim requirement from ^0.23 to ^0.23 || ^0.24 by @dependabot in https://github.com/martin-georgiev/postgresql-for-doctrine/pull/112
    • Add support for JsonTypeof function by @mpiot in https://github.com/martin-georgiev/postgresql-for-doctrine/pull/115

    New Contributors

    • @jenkoian made their first contribution in https://github.com/martin-georgiev/postgresql-for-doctrine/pull/106
    • @dependabot made their first contribution in https://github.com/martin-georgiev/postgresql-for-doctrine/pull/112
    • @mpiot made their first contribution in https://github.com/martin-georgiev/postgresql-for-doctrine/pull/115

    Full Changelog: https://github.com/martin-georgiev/postgresql-for-doctrine/compare/v1.7.0...v1.8.0

    Source code(tar.gz)
    Source code(zip)
  • v1.7.0(Feb 10, 2022)

    #105 - Add support OVERLAPS for date intervals (thanks to @gallyamow) #104 - Add support for DISTINCT and ORDER BY in STRING_AGG (kudos to @bigwhoop) #103 - Correct namespace used in integration guide (by @Gemorroj)

    Source code(tar.gz)
    Source code(zip)
  • v1.6.0(Nov 16, 2021)

    • Boolean array type (thanks to @ajgarlag)
    • Fix for a bug for quotes in text array type (thanks to @ksd-krauzand)
    • Various updates in docs, QA tools and CI
    Source code(tar.gz)
    Source code(zip)
  • v1.5.3(Nov 14, 2021)

  • v1.5.2(Jan 24, 2021)

    • #81 Use || in composer.json
    • #82 Run CI static analysis step for all tested PHP versions
    • #83 Use local version of php-security-checker
    • #84 Improve PHPUnit setup
    Source code(tar.gz)
    Source code(zip)
  • v1.5.1(Dec 4, 2020)

  • v1.5.0(Jun 7, 2020)

  • v1.4.1(Apr 22, 2020)

  • v1.4.0(Apr 13, 2020)

  • v1.3.0(Mar 9, 2020)

  • v1.2.2(Nov 23, 2019)

  • v1.2.1(Aug 4, 2019)

  • v1.2(May 29, 2019)

    • #48 TO_TSVECTOR, TO_TSQUERY, TO_JSON and TO_JSONB accept more varied arguments (thanks to @magnusnordlander)
    • #47 Add missing steps for adding own types based on official Doctrine documentation (thanks to @bednic)
    • #45 Add some examples and known common errors
    Source code(tar.gz)
    Source code(zip)
  • v1.1(Feb 20, 2019)

  • v1.0.1(Feb 1, 2019)

    This maintenance and bugfix release:

    • #39 Speeds up time for global function resolving
    • #40 Fixes transformation of empty strings (thanks to @ossinkine)
    • Adds some changes that improve the developer experience (#38, #37, #36, #35)
    Source code(tar.gz)
    Source code(zip)
  • v1.0(Sep 2, 2018)

    After more than 3 years of identifying and testing the most useful PostgreSQL json(b) and array data types features in Doctrine projects, it is finally time for this long-awaited stable release.

    Source code(tar.gz)
    Source code(zip)
  • v0.12(Aug 20, 2018)

    • Deprecate ArrayAreOverlapingEachOther and favour Overlaps. These two DQL functions are identical and v1.0 will see ArrayAreOverlapingEachOther removed.
    • Update confusing language in function classes inheriting AbstractFunction.
    • Add functional tests for the query functions so there are some real-life examples for reference.
    • Break-down README in several self-contained documents.
    Source code(tar.gz)
    Source code(zip)
  • v0.11(Jul 31, 2018)

    This release comes with no new features. It fixes some issues and edge-cases that were not properly handled before (eg resolving #17, throwing more often exceptions when bad data is detected). It also addresses numerous previously neglected housekeeping todos like:

    • Dropping support for PHP 5.5 which is EOL. This means the minimum PHP version is now 5.6.
    • Applying automated code style check.
    • Applying fixes reported by static analysis.
    • Updating Travis and Scrutinizer configurations. The CI pipeline checks for more stuff and does this in a better way.
    Source code(tar.gz)
    Source code(zip)
  • 0.10(Mar 21, 2017)

    New functions support:

    • ARRAY_DIMS
    • ARRAY_NDIMS
    • ARRAY_TO_JSON
    • ROW_TO_JSON
    • TO_JSON
    • TO_JSONB
    • UNNEST
    • JSON_ARRAY_LENGTH
    • JSON_EACH
    • JSON_EACH_TEXT
    • JSON_OBJECT_KEYS
    • JSON_STRIP_NULLS
    • JSONB_INSERT
    • JSONB_SET
    • JSONB_STRIP_NULLS
    Source code(tar.gz)
    Source code(zip)
  • 0.9(Mar 2, 2017)

Owner
Martin Georgiev
Developing for the web since 2003.
Martin Georgiev
Independent query builders for MySQL, PostgreSQL, SQLite, and Microsoft SQL Server.

Aura.SqlQuery Provides query builders for MySQL, Postgres, SQLite, and Microsoft SQL Server. These builders are independent of any particular database

Aura for PHP 424 Dec 12, 2022
PHP Object Model Manager for Postgresql

POMM: The PHP Object Model Manager for Postgresql Note This is the 1,x version of Pomm. This package is not maintained anymore, the stable Pomm 2.0 is

Grégoire HUBERT 161 Oct 17, 2022
Support for many missing PostgreSQL specific features

Laravel supports many different databases and therefore has to limit itself to the lowest common denominator of all databases. PostgreSQL, however, of

Tobias Petry 359 Jan 3, 2023
phpMyFAQ - Open Source FAQ web application for PHP and MySQL, PostgreSQL and other databases

phpMyFAQ 3.1 What is phpMyFAQ? phpMyFAQ is a multilingual, completely database-driven FAQ-system. It supports various databases to store all data, PHP

Thorsten Rinne 547 Dec 27, 2022
Laravel Thermite is an extended PostgreSQL Laravel database driver to connect to a CockroachDB cluster.

Laravel Thermite Laravel Thermite is an extended PostgreSQL Laravel database driver to connect to a CockroachDB cluster. ?? Supporting If you are usin

Renoki Co. 9 Nov 15, 2022
A simple library to access and manipulate database records. Built on top of Dibi and hardwired for PostgreSQL.

grifart/tables A simple library to access and manipulate database records. Built on top of Dibi and hardwired for PostgreSQL. This library is develope

GRIFART 5 Nov 11, 2022
Orm is a simple database abstraction layer that supports postgresql.

Orm What is it Orm is a simple database abstraction layer that supports postgresql. Welcome to join us or star us for encouragement. Requires php 8.1

null 2 Sep 28, 2022
Doctrine Object Relational Mapper (ORM)

3.0.x 2.9.x 2.8.x Doctrine 2 is an object-relational mapper (ORM) for PHP 7.1+ that provides transparent persistence for PHP objects. It sits on top o

Doctrine 9.5k Jan 2, 2023
Spot v2.x DataMapper built on top of Doctrine's Database Abstraction Layer

Spot DataMapper ORM v2.0 Spot v2.x is built on the Doctrine DBAL, and targets PHP 5.4+. The aim of Spot is to be a lightweight DataMapper alternative

Spot ORM 602 Dec 27, 2022
:gem: Simple MySQLi Abstraction Layer + Doctrine/DBAL support

?? Simple MySQLi Class This is a simple MySQL Abstraction Layer compatible with PHP 7+ that provides a simple and secure interaction with your databas

Lars Moelleken 40 Sep 5, 2022
Doctrine Database Abstraction Layer

Doctrine DBAL 4.0-dev 3.0 2.13 N/A N/A Powerful database abstraction layer with many features for database schema introspection, schema management and

Doctrine 8.9k Dec 28, 2022
A drop-in Doctrine ORM 2 implementation for Laravel 5+ and Lumen

Laravel Doctrine ORM A drop-in Doctrine ORM 2 implementation for Laravel 5+ $scientist = new Scientist( 'Albert', 'Einstein' ); $scientist->a

Laravel Doctrine 777 Dec 17, 2022
Psalm Stubs for doctrine/mongodb-odm library

doctrine-mongodb-psalm-plugin A Doctrine plugin for Psalm (requires Psalm v4). Installation: $ composer require --dev runtothefather/doctrine-mongodb-

Evgeny 6 Jun 15, 2022
Provides integration for Doctrine with various Symfony components.

Doctrine Bridge The Doctrine bridge provides integration for Doctrine with various Symfony components. Resources Contributing Report issues and send P

Symfony 3k Dec 23, 2022
Doctrine PHP mapping driver

WORK IN PROGRESS! Doctrine PHP mapping driver Alternative mapping driver that allows to write mappings in PHP. Documentation Associations examples TOD

Andrey Klimenko 3 Aug 15, 2021
Doctrine extension to persist spatial data objects.

doctrine-Spatial Doctrine-spatial is a doctrine extension. It implements spatial types and functions. As exemple, this extension can help you to know

LongitudeOne 36 Jan 7, 2023
Monadic Doctrine repositories helper classes and services.

Doctrine Repository Monadic Helper Description This project provides the necessary classes and services to use Doctrine repositories in a more functio

(infinite) loophp 10 Aug 29, 2022
🔌 A Doctrine DBAL Driver implementation on top of Swoole Coroutine PostgreSQL extension

Swoole Coroutine PostgreSQL Doctrine DBAL Driver A Doctrine\DBAL\Driver implementation on top of Swoole\Coroutine\PostgreSQL. Getting started Install

Leo Cavalcante 19 Nov 25, 2022
Enhancements to Sublime Text sidebar. Files and folders.

Sidebar Enhancements In other languages Japanese - http://taamemo.blogspot.jp/2012/10/sublime-text-2-sidebarenhancements.html?m=1 Russian - https://ww

Tito 2.1k Dec 27, 2022
GeoSpatial integration on Laravel 5.2+ that supports MySQL and PostgreSQL.

Features GeoSpatial integration on Laravel 5.2+: Create geospatial columns using Schema and migrations Save and retrieve geospatial attributes using d

Eleven 47 Dec 22, 2022