0.4.0 - 2024-08-31
- Closures passed as the
$fragments
parameter into methods defined inTableGateway
interface will receive a subclass ofFragmentListBuilder
(created byTableLocator::createBuilder()
for that table name) rather than a subclass ofStatement
. Before:now:$gateway->delete(fn(Delete $delete) => $delete->where->and('foo = bar'));
Previous behaviour is supported by the new$gateway->delete(fn(FluentBuilder $fb) => $fb->sqlCondition('foo = bar'));
*WithAST()
methods. - Methods of
FluentBuilder
that accepted callbacks to configure the created builder instances, e.g.join()
, now return builder objects that proxyFluentBuilder
methods. Before:now:$builder->join($otherTable, fn(JoinBuilder $jb) => $jb->left()->onForeignKey()) ->outputColumns(fn(ColumnsBuilder $cb) => $cb->except(['foo']));
Callbacks are still accepted but deprecated.$builder ->join($otherTable) ->left() ->onForeignKey() ->outputColumns() ->except(['foo']);
- Strings passed to
createExists()
,exists()
, andjoin()
methods ofFluentBuilder
are now treated as SELECT statements rather than table names:Table names can still be passed as instances of$builder ->join('select foo from bar as baz');
TableName
orQualifiedName
. - Constructor of
TableSelect
accepts an instance ofFragmentList
rather than separate$fragments
and$parameters
. FluentBuilder::join()
will join on foreign key by default if possible. If an unconditional join is needed, this should be explicitly requested:$builder ->join($otherTable) ->unconditional();
AdHocStatement
interface withdeleteWithAST()
,insertWithAST()
,selectWithAST()
, andupdateWithAST()
methods. Those accept closures that receive the relevant subclass ofStatement
as parameter.GenericTableGateway
implements this interface.FragmentListBuilder::__clone()
: this now clones the current state of the builder allowing to safely use a semi-configured one as a prototype.GenericTableGateway::createBuilder()
method that callsTableLocator::createBuilder()
internally using the table's name from that gateway.TableSelect::fetchFirst()
method that is shorthand for$select->getIterator()->current()
TableLocator::select($name, $fragments, $parameters)
method that is shorthand for$locator->createGateway($name)->select($fragments, $parameters)
0.3.0 - 2024-08-06
- Changed typehint of
$gatewayFactories
parameter forTableLocator::__construct()
fromarray
toiterable
, allowing to use e.g.tagged_iterator
from Symfony's DI container in its place. - Implementations of methods defined in
metadata\Columns
,metadata\PrimaryKey
, andmetadata\References
interfaces were moved frommetadata\Table*
implementations into traits. This separates the code that loads metadata from DB / cache and the code that accesses that metadata, allowing reuse of the latter:ArrayOfColumns
trait now contains a$columns
property and implementations ofColumns
methods working with it.ArrayOfPrimaryKeyColumns
trait now contains$columns
and$generated
properties and implements methods ofPrimaryKey
working with these.ArrayOfForeignKeys
trait has$foreignKeys
,$referencing
, and$referencedBy
properties as well as implementations ofReferences
methods using these.
- Additionally,
metadata\TableColumns
defined a new protectedassertCorrectRelkind()
method that can be easily overridden in child class if working with relations that are not ordinary tables.
0.2.1 - 2024-07-24
Fixed package name in composer.json
: the intended sad_spirit/pg_gateway
instead of sad_spirit/pg-gateway
(dash replaced by underscore).
0.2.0 - 2024-06-14
metadata\TableName
class replacingQualifiedName
frompg_builder
package.metadata\TableOIDMapper
interface and its defaultmetadata\CachedTableOIDMapper
implementation. This is used for checking the relation type when creating an implementation ofTableDefinition
and may be used to ease mapping of result columns when usingResult::getTableOID()
.TableDefinitionFactory
interface and its defaultOrdinaryTableDefinitionFactory
implementation. The latter will return an instance ofOrdinaryTableDefinition
only for relations that exist inpg_catalog.pg_class
and contain 'r' (ordinary table) in therelkind
column.TableLocator::setTableDefinitionFactory()
andTableLocator::getTableDefinitionFactory()
. If the factory is not explicitly set, the latter will create and return an instance ofOrdinaryTableDefinitionFactory
.TableLocator::getTableDefinition()
returning an implementation ofTableDefinition
for the given table. It uses the configured instance ofTableDefinitionFactory
.TableGatewayFactory::createBuilder()
method returning a subclass of a new abstractbuilders\FragmentListBuilder
class. The method is called by the newTableLocator::createBuilder()
method which will return an instance of defaultbuilders\FluentBuilder
implementation if the factories did not create a specific one.NameMappingGatewayFactory
implementation ofTableGatewayFactory
that maps DB schemas to PHP namespaces and "snake-case"table_name
to "StudlyCaps"TableName
.- Base abstract
CustomFragment
andCustomSelectFragment
classes andParametrizedFragment
decorator, those can be used to add custom cacheable fragments. - Fragments and builders adding Common Table Expressions to query's
WITH
clause. It is possible to specify those either as an SQL string or as a wrapper forSelectProxy
(i.e. a result ofTableGateway::select()
).
metadata\TableName
is used throughout the package in place ofpg_builder
'sQualifiedName
. Instances of the new class do not need to be cloned and always contain two name parts (schema and relation) which makes working with them a bit easier.metadata\Columns
,metadata\PrimaryKey
, andmetadata\References
are now interfaces with the former logic residing inmetadata\TableColumns
,metadata\TablePrimaryKey
,metadata\TableReferences
respectively. The main reason is that custom implementations are needed for views and other relations other than ordinary tables.OrdinaryTableDefinition
is a default implementation ofTableDefinition
, which returns the instances of the above metadata classes.TableGateway
andSelectProxy
interfaces no longer extendTableDefinition
, they extend a newTableAccessor
interface with agetDefinition()
method.- Builder methods of
GenericTableGateway
were moved toFluentBuilder
. Instances of that class are returned byTableLocator::createBuilder()
by default, its methods now return$this
allowing to chain calls. The actual fragments being created are added to theFragmentList
eventually returned bygetFragment()
- Constructor of
TableLocator
accepts an array ofTableGatewayFactory
implementations rather than a single one. There is also a newaddTableGatewayFactory()
method. The factories will be called in the order added. TableGatewayFactory::create()
renamed tocreateGateway()
.TableLocator::get()
is nowTableLocator::createGateway()
. It will no longer return the same instance ofTableGateway
for the same table name. It also uses an instance ofTableDefinitionFactory
under the hood, so by default only gateways to existing ordinary tables will be created.setPriority()
method ofVariablePriority
trait is now protected rather than public. PreviouslyFragment
s using that trait were essentially mutable.- Depend on
pg_wrapper
andpg_builder
2.4
GenericTableGateway::create()
factory method. It is no longer necessary to access private properties in this and the remaining logic was moved toTableLocator::createGateway()
.
0.1.0 - 2023-09-13
Initial release on GitHub.