kinetis / query-builder
A thin, parameterized SQL query builder over kinetis/persistence's MySQL and Postgres drivers, with portable row-to-DTO mapping and pagination envelopes. Usable standalone. Not an ORM: no relationships, no migrations, no change-tracking.
Requires
- php: ^8.4
- kinetis/persistence: ^1.4.1
Requires (Dev)
- infection/infection: ^0.35.0
- kinetis/framework: ^1.12.3
- phpstan/phpstan: ^2.2.8
- phpunit/phpunit: ^13.3.3
- vimeo/psalm: ^6.17
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
kinetis/query-builder
A thin, parameterized SQL query builder for MySQL and PostgreSQL
Part of Kinetis, a non-blocking PHP framework for
API-first applications, developed in the
kinetis-dev/kinetis monorepo.
Usable standalone: in production it depends only on
kinetis/persistence.
Parameterized selects, joins, subqueries, set operations, CTEs, row
locks, inserts, upserts, updates and deletes over the SQL shared by
MySQL 8.4, MariaDB 11.4 and PostgreSQL 16, run through
kinetis/persistence's drivers, with its own row-to-DTO mapping and
pagination envelopes. Not an ORM: no relationships, no change-tracking,
no save()-on-a-model.
use Kinetis\Persistence\ConnectionDefinition; use Kinetis\Persistence\SqlConnectionFactory; use Kinetis\QueryBuilder\Query; // Build the client once and reuse it across units of work. $db = SqlConnectionFactory::create(new ConnectionDefinition( dialect: 'mysql', host: 'db.internal', database: 'shop', user: 'shop', password: $password, )); $orders = new Query($db) ->table('orders') ->where('customer_id', '=', $customerId) ->where('status', '!=', 'cancelled') ->orderBy('created_at', 'desc') ->limit(20) ->get(OrderRow::class); // OrderRow is your own row DTO
The connection's type selects the SQL dialect, and a Query built on a
transaction runs inside it. What the host owns — client lifetime and a
TransactionGuard per unit of work — is described in
kinetis/persistence.
With Kinetis
composer require kinetis/query-builder kinetis/database-bridge
Install both: kinetis/database-bridge
binds the connection from DB_* configuration but does not install the
query builder. An application then injects MysqlLink or PostgresLink
and constructs new Query($link) per statement with no wiring of its
own.
Installation
composer require kinetis/query-builder
Requires PHP 8.4+ and kinetis/persistence,
plus the PHP extension for the driver you use. Full documentation:
kinetis.dev/docs/query-builder.html.
License
MIT — see LICENSE.