Download the PHP package sad_spirit/pg_builder without Composer
On this page you can find all versions of the php package sad_spirit/pg_builder. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download sad_spirit/pg_builder
More information about sad_spirit/pg_builder
Files in sad_spirit/pg_builder
Package pg_builder
Short Description Query builder for Postgres backed by SQL parser
License BSD-2-Clause
Informations about the package pg_builder
sad_spirit/pg_builder
This is a query builder for Postgres with a twist: it contains a partial1 reimplementation of PostgreSQL's own query parser. This sets it aside from the usual breed of "write-only" query builders:
- Query is represented as an Abstract Syntax Tree quite similar to PostgreSQL's internal representation.
- Query parts can be added to the AST either as objects or as strings (that will be processed by Parser).
- Nodes can be removed and replaced in AST.
- AST can be analyzed and transformed, the package takes advantage of this to allow named parameters like
:foo
instead of standard PostgreSQL's positional parameters$1
and to infer parameters' types from SQL typecasts. - Almost all syntax available for
SELECT
(andVALUES
) /INSERT
/UPDATE
/DELETE
/MERGE
in PostgreSQL 17 is supported, query being built is automatically checked for correct syntax.
Substantial effort was made to optimise parsing, but not parsing is faster anyway, so there are means to cache parts of AST and the resultant query.
Usage example
the last echo
statement will output something like
if targeting Connection
and something like
if targeting PDO
Installation
Require the package with composer:
pg_builder requires at least PHP 8.2. Either native pgsql extension with pg_wrapper package or PDO with pgsql support can be used to run the built queries.
Minimum supported PostgreSQL version is 12.
It is highly recommended to use PSR-6 compatible cache in production.
Documentation
For in-depth description of package features, visit pg_builder manual.
1: "Partial" here means the following: PostgreSQL grammar file src/backend/parser/gram.y
is about 19K lines long.
Of these about 5K lines are used for SELECT
/ INSERT
/ UPDATE
/ DELETE
/ MERGE
queries and are reimplemented here.
All versions of pg_builder with dependencies
ext-ctype Version *