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
Note: master branch is being upgraded for PHP 8.2+ and new syntax of Postgres 17. Branch 2.x contains the stable version supporting PHP 7.2+ and Postgres 16.
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 16 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
Documentation
Is in the wiki
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 *