The Game Panel Design record
The Game Panel
ADR-0008 Accepted

Build database access directly on PDO

Created
Decided
Versions
History

Context

The panel needs database access: connections, a way to build queries, and a way to build and change the schema. Existing database abstraction layers provide all of that, but each one brings a great deal of code and a large number of third-party libraries with it, which adds to the panel's footprint and complicates it.

Decision

I will build the database component directly on PHP's PDO extension, with its own connections, query builder and schema builder, rather than on an existing database abstraction layer.

Alternatives

An existing database abstraction layer, providing connections, query building and schema building ready-made. I rejected this because every one available pulls in so much code and so many third-party libraries that it complicates the panel and adds to its footprint.

Consequences

Easier:

  • The panel's footprint will stay small. The database component will need the PDO extension and no further libraries.
  • The component's API will follow the panel's own conventions, such as configuration held in typed objects and connections injected through an attribute.

Harder:

  • The component will own everything a database abstraction layer would otherwise provide, and its correctness: connection handling, differences between drivers, SQL generation, identifier quoting and bound values.

Constrained:

  • Supporting another database will mean writing that support inside the component, as the hidden driver support in ADR-0007 anticipates.

Sources

  • Commit 4e4b8bf, "Create connection factory", , on the branch of PR #30: the first code creating connections directly with PDO, which is created.
  • PR #30, feat(database): Add the database component, merged and squashed as 560e9ab: the component built on PDO, which is decided.
  • composer.json at 560e9ab: the PDO extension required, and no database abstraction layer.
  • The decision and its reason, that existing database abstraction layers pull in so much code and so many third-party libraries that they complicate the panel and add to its footprint: first written down on , with no record of when they were weighed.
  • Issues #41, #42 and #48, and : defects in identifier quoting, bindings and connection options, which show the correctness the component owns, taken from what followed rather than anticipated.

Source adr/0008-direct-pdo.md · commit d6910e4 · exported