Skip to content

v2.3.0 - Knex compatibility layer for MySQL and PostgreSQL

Latest

Choose a tag to compare

@jeremydaly jeremydaly released this 09 Jun 02:17
b1e8100

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 literal BEGIN/COMMIT/ROLLBACK SQL Knex issues and maps it to the Data API transaction lifecycle.
  • Query-builder coverage for both engines: selects, the where family, joins, aggregates, ordering and pagination, unions, subqueries, CTEs, insert/update/del, returning, increment/decrement, and onConflict().merge() upserts.
  • knex is 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 with bind 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 ... SELECT was tagged as a generic query instead of a SELECT, 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 >= 20 and 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 nested trx.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.0

To use the Knex helpers, install knex alongside it (it's an optional peer dependency):

npm install knex

Feedback

If you run into anything or have suggestions, please open an issue.


Full Changelog: v2.2.0...v2.3.0