I am pleased to announce the release of pg_builder and pg_wrapper packages for PHP updated for Postgres 17 syntax.
pg_builder is a query builder for Postgres backed by a partial PHP reimplementation of PostgreSQL's own SQL parser. It supports almost all syntax available in Postgres 17 for SELECT
(and VALUES
), INSERT
, UPDATE
, DELETE
, and MERGE
queries.
With pg_builder it is possible to start with a manually written query, parse it into an Abstract Syntax Tree, add query parts (either as Node objects or as strings) to this tree or remove them, and finally convert the tree back to an SQL string.
Release highlights:
MERGE
statement improvements: RETURNING
clause, WHEN NOT MATCHED BY SOURCE
action, possible to use in WITH
;json()
, json_scalar()
, json_serialize()
, json_exists()
, json_query()
, json_value()
, json_table()
.The package can be downloaded from GitHub or installed with Composer:
$ composer require sad_spirit/pg_builder
pg_wrapper provides converters for PostgreSQL data types and an object-oriented wrapper for PHP's native pgsql extension that uses these converters. Conversion of query result fields is done automatically using database metadata, query parameters may require specifying type.
For those types where a corresponding native PHP type or class is available it is used (text
-> string
, timestamp
-> DateTimeImmutable
, hstore
-> associative array, etc.). For other types (geometric types, ranges) the package provides custom classes. If base types can be converted, then composite types, arrays, ranges using those can be handled as well.
Release highlights:
ENUM
types and PHP's string-backed enums;The package can be downloaded from GitHub or installed with composer
$ composer require sad_spirit/pg_wrapper