Skip to content

PostgreSQL enhancements for Doctrine. Provides support for advanced data types (json, jssnb, arrays), text search, array operators and jsonb specific functions.

License

Notifications You must be signed in to change notification settings

martin-georgiev/postgresql-for-doctrine

Repository files navigation

Scrutinizer Code Quality Coverage Status Latest Stable Version Total Downloads

PostgreSQL for Doctrine

Enhances Doctrine with PostgreSQL-specific features and functions. Supports PostgreSQL 9.4+ and PHP 8.1+.

Quick Start

// Register types with Doctrine
Type::addType('jsonb', "MartinGeorgiev\\Doctrine\\DBAL\\Types\\Jsonb");
Type::addType('text[]', "MartinGeorgiev\\Doctrine\\DBAL\\Types\\TextArray");

// Use in your Doctrine entities
#[ORM\Column(type: 'jsonb')]
private array $data;

#[ORM\Column(type: 'text[]')]
private array $tags;

// Use in DQL
$query = $em->createQuery('
    SELECT e 
    FROM App\Entity\Post e 
    WHERE CONTAINS(e.tags, ARRAY[:tags]) = TRUE
    AND JSON_GET_FIELD(e.data, :field) = :value
');

🚀 Features Highlight

This package provides comprehensive Doctrine support for PostgreSQL features:

Data Types

  • Array Types
    • Integer arrays (int[], smallint[], bigint[])
    • Text arrays (text[])
    • Boolean arrays (bool[])
    • JSONB arrays (jsonb[])
  • JSON Types
    • Native JSONB support
    • JSON field operations
    • JSON construction and manipulation

PostgreSQL Operators

  • Array Operations
    • Contains (@>)
    • Is contained by (<@)
    • Overlaps (&&)
    • Array aggregation with ordering
  • JSON Operations
    • Field access (->, ->>)
    • Path operations (#>, #>>)
    • JSON containment and existence operators

Functions

  • Text Search
    • Full text search (to_tsvector, to_tsquery)
    • Pattern matching (ILIKE, SIMILAR TO)
    • Regular expressions
  • Array Functions
    • Array aggregation (array_agg)
    • Array manipulation (array_append, array_prepend)
    • Array dimensions and length
  • JSON Functions
    • JSON construction (json_build_object, jsonb_build_object)
    • JSON manipulation and transformation
  • Date Functions
  • Aggregate Functions

Full documentation:

📦 Installation

composer require martin-georgiev/postgresql-for-doctrine

🔧 Integration Guides

💡 Usage Examples

See our Common Use Cases and Examples for detailed code samples.

⭐ Support the Project

💖 GitHub Sponsors

If you find this package useful for your projects, please consider sponsoring the development via GitHub Sponsors. Your support helps maintain this package, create new features, and improve documentation.

Benefits of sponsoring:

  • Priority support for issues and feature requests
  • Direct access to the maintainer
  • Help sustain open-source development

Other Ways to Help

📝 License

This package is licensed under the MIT License. See the LICENSE file for details.