PHP code example of martin-georgiev / postgresql-for-doctrine
1. Go to this page and download the library: Download martin-georgiev/postgresql-for-doctrine library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
martin-georgiev / postgresql-for-doctrine example snippets
use Doctrine\DBAL\Types\Type;
use MartinGeorgiev\Doctrine\DBAL\Type as PostgresType;
// Register types with Doctrine
Type::addType('jsonb', "MartinGeorgiev\\Doctrine\\DBAL\\Types\\Jsonb");
Type::addType('text[]', "MartinGeorgiev\\Doctrine\\DBAL\\Types\\TextArray");
Type::addType('numrange', "MartinGeorgiev\\Doctrine\\DBAL\\Types\\NumRange");
// Use in your Doctrine entities
#[ORM\Column(type: PostgresType::JSONB)]
private array $data;
#[ORM\Column(type: PostgresType::TEXT_ARRAY)]
private array $tags;
#[ORM\Column(type: PostgresType::NUMRANGE)]
private NumericRange $priceRange;
// 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
');