-
Notifications
You must be signed in to change notification settings - Fork 6
Home
Alexey Borzov edited this page Sep 20, 2017
·
6 revisions
This is a query builder for Postgres backed by a partial PHP reimplementation of PostgreSQL's own query parser. All syntax available for SELECT
(and VALUES
), INSERT
, UPDATE
, and DELETE
queries in Postgres 10 is supported with minor omissions. Highlights:
- Query is represented by an Abstract Syntax Tree consisting of
Node
s. This is quite similar to what Postgres does internally. - Query parts (e.g. new columns for a
SELECT
or parts of aWHERE
clause) can usually be added to the AST either asNode
s or as strings. Strings are processed byParser
, so query being built is automatically checked for correct syntax. - Nodes can be removed and replaced in AST (e.g. calling
join()
method of a node inFROM
clause replaces it with aJoinExpression
node having the original node as its left argument). - 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.
The package can be used on its own but using it together with sad_spirit\pg_wrapper
is highly recommended: that package provides transparent conversion from PHP types to PostgreSQL ones and back. StatementFactory
, NativeStatement
, and ParserAwareTypeConverterFactory
classes are responsible for integration with pg_wrapper
.
StatementFactory
helper classStatement
classesNode
andNodeList
base classes- Helper methods of
Node
subclasses - Parsing SQL,
Parser
class - Modifying AST and building SQL,
Treewalker
interface and implementations - Running the built queries, integration with
pg_wrapper
- Caching options
- Exception classes