GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat(knex): allow enabling the RETURNING clause via the knex config by nm3xyz · Pull Request #3728 · feathersjs/feathers

Conversation

@nm3xyz

@nm3xyz nm3xyz commented Oct 31, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Allow enabling the RETURNING clause via the knex configuration

Branch: feat/knex-returning-config (head: nm3xyz/feathers, commit 173ad8f)
Repo: feathersjs/feathers — base dove @ 8c007bc (v5.0.53, the repository default branch)


Summary

  • Tell us about the problem your pull request is solving.

KnexAdapter._create decides whether to use the RETURNING clause in the insert statement with a hard-coded list of clients:

const RETURNING_CLIENTS = ['postgresql', 'pg', 'oracledb', 'mssql', 'sqlite3']
...
const returning = RETURNING_CLIENTS.includes(client.driverName) ? [this.id] : []

Any database that does support RETURNING but is not in that list — Firebird via knex-firebird-dialect is a concrete example — can not get the id back from the insert. The adapter then falls back to using the returned row value / an additional _get, which either does not work or costs an extra query.

This PR lets the knex configuration opt in (or out of the default) with a returning boolean:

const db = knex({
  client: knexFirebirdDialect,
  connection: { /* ... */ },
  returning: true
})

Implementation

export const supportsReturning = (client: Knex.Client) => {
  const { returning } = (client.config || {}) as ReturningConfig

  return Boolean(returning) || RETURNING_CLIENTS.includes(client.driverName)
}
  • A truthy client.config.returning enables the clause.
  • If it is not set or falsy, the existing RETURNING_CLIENTS check is used, so behaviour for every currently supported database is unchanged.

_create now calls supportsReturning(client) instead of the inline check.

Tests

Added a returning clause support suite in packages/knex/test/index.test.ts (no database required, the client and the insert are stubbed):

  • default list is used when the option is not set (postgresql, oracledb, sqlite3 → true; node-firebird-driver-native → false)
  • the option enables it for a client outside the default list
  • a falsy option falls back to the default list (false + Firebird → false, false + PostgreSQL → true)
  • _create actually passes [id] to insert when the option is enabled, and [] when it is not

Full package suite: 336 passing, 20 pending (sqlite), plus eslint and prettier clean on the changed files.

Docs

Added a short "RETURNING clause support" section to docs/api/databases/knex.md, documenting the returning knex option and the Firebird example.

Other Information

  • Are there any open issues that are related to this? — None found; this came up while porting a Feathers service to Firebird.
  • Is this PR dependent on PRs in other repos? — No.

Files changed: packages/knex/src/adapter.ts, packages/knex/test/index.test.ts, docs/api/databases/knex.md (99 insertions, 2 deletions).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@nm3xyz
feat(knex): allow enabling the RETURNING clause via the knex config
173ad8f
The insert in `_create` only uses the `RETURNING` clause for a hard-coded
list of clients. Databases that support it but are not in that list, like
Firebird via knex-firebird-dialect, can not return the id of created
records and fall back to a second query.

The `returning` option of the knex configuration (available as
`client.config.returning`) now takes precedence. If it is not set or
falsy, the existing list of clients is still used so the behaviour for
all currently supported databases is unchanged.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@nm3xyz
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.