kinetis / database-bridge
Kinetis wiring for kinetis/persistence and kinetis/orm: DB_* connection configuration and the default link binding, SQL spans through Kinetis telemetry, a lazy request-scoped TransactionGuard whose cleanup is registered once a scope resolves it, and, with kinetis/orm installed, AOT-compiled entity m
Requires
- php: ^8.4
- kinetis/framework: ^1.11.1
- kinetis/persistence: ^1.4.0
- psr/log: ^3.0.2
Requires (Dev)
- infection/infection: ^0.35.0
- kinetis/mcp: ^1.5.2
- kinetis/orm: ^1.0.0
- kinetis/query-builder: ^1.5.0
- kinetis/queue: ^1.3.2
- nyholm/psr7: ^1.8.2
- phpstan/phpstan: ^2.2.8
- phpunit/phpunit: ^13.3.3
- vimeo/psalm: ^6.17
Suggests
- kinetis/migrations: Migration runner and migrate commands, connecting through this package's connection policy.
- kinetis/orm: Attributed entities, typed repositories and a request-scoped EntityManager over the link this package binds, with entity metadata compiled into the AOT cache.
- kinetis/query-builder: Parameterized queries and row-to-DTO mapping over the MysqlLink/PostgresLink this package binds.
Provides
None
Conflicts
None
Replaces
None
README
kinetis/database-bridge
Kinetis wiring for kinetis/persistence
Part of Kinetis, a non-blocking PHP framework for API-first applications, developed in the kinetis-dev/kinetis monorepo.
kinetis/persistence
depends on no Kinetis package. This package connects it to a Kinetis
application: the DB_* configuration keys, the default connection
binding, SQL spans through Kinetis telemetry, a lazy request-scoped
TransactionGuard, and, with kinetis/orm
installed, compiled entity metadata and a request-scoped EntityManager.
composer require kinetis/database-bridge
With DB_CONNECTION set, application code constructor-injects the
connection and a TransactionGuard with no bootstrap code of its own:
use Kinetis\Persistence\Contract\MysqlLink; use Kinetis\Persistence\Contract\SqlTransaction; use Kinetis\Persistence\TransactionGuard; final readonly class OrderController { public function __construct( private MysqlLink $db, private TransactionGuard $transactions, ) {} #[Post('/orders')] public function store(): array { return $this->transactions->transaction($this->db, static function (SqlTransaction $tx): array { $tx->execute('UPDATE inventory SET stock = stock - 1 WHERE sku = ?', ['SKU-1']); return ['status' => 'created']; }); } }
Provides
Installing this package is what opts it in — it registers the
following automatically, through the extra.kinetis declaration in its
composer.json (see
kinetis.dev/docs/cli.html):
- Service binding: with
DB_CONNECTIONset, the default connection is built and bound under its dialect contract (Kinetis\Persistence\Contract\MysqlLinkorContract\PostgresLink) before your ownbootstrap.phpruns — your registration wins on the same binding. No connection is built whenDB_CONNECTIONis unset. Named connections stay explicit wiring:Kinetis\DatabaseBridge\ConnectionFactory::fromConfig($config, 'reporting'). - Lazy transaction cleanup: every request scope — an HTTP request, a
queued job, an MCP message, a command — receives a lazy
Kinetis\Persistence\TransactionGuardbinding. Resolving it builds the guard and registersrollbackDangling()on that scope's disposal; a scope that never resolves it builds no guard and registers no cleanup. - Telemetry: every client this package builds reports its queries
and transactions through Kinetis telemetry, so installing
kinetis/telemetryturns them into spans. - ORM wiring, once
kinetis/ormis installed alongside it (this package does not install it): classes marked#[Entity]under the project's PSR-4 roots are compiled into the AOT cache with the rest of discovery,Kinetis\Orm\OrmFactoryis bound for the worker, and every request scope receives a lazyKinetis\Orm\EntityManager, opened on first resolution and closed with that scope. WithoutDB_CONNECTION, resolving either throwsKinetis\DatabaseBridge\Exception\DatabaseNotConfiguredException. See kinetis.dev/docs/orm.html.
kinetis/migrations
requires this package and registers its own migrate* commands, which
connect through ConnectionFactory::singleSession().
kinetis/query-builder
needs no binding: construct new Query($link) per statement over the
link this package binds. How each capability composes with the bridge:
kinetis.dev/docs/persistence.html.
Configuration
Read from the environment (or .env) via Kinetis\Config. Every key is
scoped.
| Key | Default | Purpose |
|---|---|---|
DB_CONNECTION |
(unset: no connection built) | mysql or pgsql. |
DB_HOST |
127.0.0.1 |
Server host. |
DB_PORT |
3306 / 5432 |
Per dialect; a valid TCP port. |
DB_NAME |
app |
Database name. |
DB_USER |
app |
User. |
DB_PASSWORD |
(required) | Password. |
DB_DRIVER |
auto |
auto (native under FrankenPHP worker mode or RoadRunner, PDO otherwise), native, or pdo. |
DB_CHARSET |
utf8mb4 (MySQL) |
Connection charset. |
DB_COLLATION |
— | MySQL collation (SET NAMES ... COLLATE). |
DB_SSLMODE |
— | disable/require/verify-ca/verify-full on every driver; libpq additionally accepts allow/prefer. |
DB_SSL_CA |
— | CA bundle path for the verify modes. |
DB_SSL_CERT |
— | Client certificate for mutual TLS; requires DB_SSL_KEY. |
DB_SSL_KEY |
— | Client private key; requires DB_SSL_CERT. Postgres requires 0600 permissions. |
DB_CONNECT_TIMEOUT |
— | Seconds. |
DB_APP_NAME |
— | Postgres application_name. |
DB_COMPRESSION |
— | MySQL protocol compression. |
DB_MAX_CONNECTIONS |
8 |
Async drivers' pool width — per worker thread under FrankenPHP, per worker process under RoadRunner. |
DB_WARM_CONNECTIONS |
0 |
Connections opened at boot instead of first use — load-bearing for the mysqli driver under worker mode. |
Scoped keys follow the named-connection convention — the connection
name inserts after the first segment: DB_HOST + reporting →
DB_REPORTING_HOST. Full reference across every package:
kinetis.dev/docs/config.html.
Installation
composer require kinetis/database-bridge
Requires PHP 8.4+, kinetis/framework,
and kinetis/persistence,
plus the extension for the driver you use: ext-mysqli, ext-pgsql
(with ext-sockets), ext-pdo_mysql or ext-pdo_pgsql. Full
documentation:
kinetis.dev/docs/persistence.html.
License
MIT — see LICENSE.