Introducing pg_builder and pg_wrapper packages for PHP

From: Alexey Borzov <borz_off(at)cs(dot)msu(dot)su>
To: pgsql-announce(at)postgresql(dot)org
Subject: Introducing pg_builder and pg_wrapper packages for PHP
Date: 2017-09-20 18:10:03
Message-ID: 00713789-05fa-eb58-c456-d3f069a6f0e1@cs.msu.su
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-announce


I'm pleased to announce a new version of pg_builder, updated to support new
syntax features of upcoming Postgres 10. Its sister package pg_wrapper is
updated as well.

What's more important, both packages now have user documentation.

pg_builder version 0.2.1
---------------------------

pg_builder is a query builder for Postgres backed by a partial PHP
reimplementation of PostgreSQL's own query parser. Current version supports all
syntax available for SELECT (and VALUES), INSERT, UPDATE, and DELETE queries in
Postgres 10 with minor omissions.

* Query is represented by an Abstract Syntax Tree consisting of Nodes. This is
quite similar to what Postgres does internally.
* Query parts (e.g. new columns for a SELECT or parts of a WHERE clause) can
usually be added to the AST either as Nodes or as strings. Strings are processed
by parser, 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
in FROM clause replaces it with a JoinExpression node having the original node
as its 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.

pg_builder can be used on its own, but using it together with pg_wrapper allows
to run the built queries and to leverage transparent conversion of query
parameters to Postgres types.

Requirements
---------------

PHP 5.3+

Links
--------

Source: https://github.com/sad-spirit/pg-builder
Documentation: https://github.com/sad-spirit/pg-builder/wiki

The package is installable with Composer
$ composer require sad_spirit/pg_builder

pg_wrapper version 0.2.2
---------------------------

pg_wrapper wraps around functions of PHP's pgsql extension and provides
transparent conversion of database types to their PHP equivalents

Postgres types supported
* Numeric types, character types, boolean, bytea
* Date and time types, intervals
* Arrays of any base type
* Ranges of any base type
* Composite types
* json / jsonb
* Geometric types
* hstore (from contrib/hstore)

For those types where a corresponding native PHP type or class is available it
is used (text -> string, timestamp -> DateTime, interval -> DateInterval, hstore
-> associative array, etc.). For other types (geometric types, ranges) the
package provides custom classes.

Conversion of query result fields is done automatically using database metadata,
query parameters may require specifying type:

$connection->executeParams(
'select typname from pg_catalog.pg_type where oid = any($1) order by typname',
[[21, 23, 25]],
['integer[]']
);

Requirements
---------------

PHP 5.3+ with pgsql extension.

Links
--------

Source: https://github.com/sad-spirit/pg-wrapper
Documentation: https://github.com/sad-spirit/pg-wrapper/wiki

The package is installable with Composer
$ composer require sad_spirit/pg_wrapper

Browse pgsql-announce by date

  From Date Subject
Next Message Stephen Frost 2017-09-21 13:10:54 PostgreSQL v10 RC 1 Released!
Previous Message David Fetter 2017-09-18 04:59:03 == PostgreSQL Weekly News - September 17 2017 ==