New Features
Knex compatibility layer for both MySQL and PostgreSQL. The new data-api-client/compat/knex subpath gives you createKnexMySQLClient() and createKnexPgClient(), which return a custom Knex client wired to the Data API. Knex doesn't accept an injected pool the way Drizzle and Kysely do, so the helpers subclass Knex's mysql2/pg dialect and override _driver() to run Knex's SQL over the Data API. (#174)
- Transactions work.
db.transaction()commits on success and rolls back when the callback throws. The compat layer intercepts the literalBEGIN/COMMIT/ROLLBACKSQL Knex issues and maps it to the Data API transaction lifecycle. - Query-builder coverage for both engines: selects, the
wherefamily, joins, aggregates, ordering and pagination, unions, subqueries, CTEs,insert/update/del,returning,increment/decrement, andonConflict().merge()upserts. knexis an optional peer dependency, so it's only required if you actually use these helpers.
Bug Fixes
These were latent in the shared compatibility layers and also affected non-Knex callers:
- pg parameter binding: the
query({ text, values }, cb)callback form dropped its bindings, so parameterized queries using node-postgres's config-object form failed withbind message supplies 0 parameters. - mysql2 callback parsing:
query(config, undefined, cb)did not pick up the third-argument callback, so bindings-less statements hung. - pg CTE command inference: a
WITH ... SELECTwas tagged as a generic query instead of aSELECT, so CTEs returned the raw response object instead of rows.
Documentation
- Reworked the README intro and added a Knex usage section.
- Restructured the version notes into a "What's New in v2.3" section plus a consolidated Changelog.
Testing
- Added query-builder coverage suites for both engines plus transaction tests, wired into
test:int:orm:knex.
Other Changes
- Declared
engines.node >= 20and added an.nvmrc. - Resolved three dev-dependency advisories via
npm audit fix(ajv, brace-expansion, cross-spawn). - Bumped vitest and @vitest/ui. (#173)
Limitations
- Nested transactions need SQL
SAVEPOINTs, which the Data API has no primitive for, so a nestedtrx.transaction(...)throws. - Streaming (
.stream()) is not supported, since the Data API has no cursor API.
Upgrade Instructions
This release is additive and backward compatible. Update the package:
npm install data-api-client@2.3.0To use the Knex helpers, install knex alongside it (it's an optional peer dependency):
npm install knexFeedback
If you run into anything or have suggestions, please open an issue.
Full Changelog: v2.2.0...v2.3.0