nette / database

💾 A database layer with a familiar PDO-like API but much more powerful. Building queries, advanced joins, drivers for MySQL, PostgreSQL, SQLite, MS SQL Server and Oracle.
https://doc.nette.org/database
Other
513 stars 108 forks source link

Support for PostgreSQL own custom types? #301

Open C-Duv opened 1 year ago

C-Duv commented 1 year ago

Hello,

It seems the library does not support PostgreSQL custom types.

Say I have the following physical_address type:

CREATE TYPE physical_address AS (
    name text,
    extra_recipient_information text DEFAULT NULL,
    street_number_and_name text,
    extra_street_information text DEFAULT NULL,
    post_office_box text,
    postal_code text,
    locality text,
    country text
);

And a table of clients:

CREATE TABLE IF NOT EXISTS clients (
    id uuid NOT NULL DEFAULT gen_random_uuid(),
    name text NOT NULL,
    address physical_address NOT NULL
);

Containing the following row:

id|name   |address                                         |
--+-------+------------------------------------------------+
… |Foo Bar|(Some Name,42th street,BP123,75001,Paris,France)|

With the following code:

$connection = new Nette\Database\Connection(…);
$some_client = $connection->fetch(
    'SELECT * FROM "clients" LIMIT 1',
)->fetch();

var_dump($some_client->address) . PHP_EOL;

It looks like address is seen as a simple string:

string(48) "(Some Name,42th street,BP123,75001,Paris,France)"

Is there a way to access sub fields? Something like:

$some_client->address->locality;
$some_client->address['locality'];