Repository navigation
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Allow enabling the
RETURNINGclause via the knex configurationBranch:
feat/knex-returning-config(head:nm3xyz/feathers, commit173ad8f)Repo:
feathersjs/feathers— basedove@8c007bc(v5.0.53, the repository default branch)Summary
KnexAdapter._createdecides whether to use theRETURNINGclause in the insert statement with a hard-coded list of clients:Any database that does support
RETURNINGbut is not in that list — Firebird viaknex-firebird-dialectis 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
returningboolean:Implementation
client.config.returningenables the clause.RETURNING_CLIENTScheck is used, so behaviour for every currently supported database is unchanged._createnow callssupportsReturning(client)instead of the inline check.Tests
Added a
returning clause supportsuite inpackages/knex/test/index.test.ts(no database required, the client and the insert are stubbed):postgresql,oracledb,sqlite3→true;node-firebird-driver-native→false)false+ Firebird →false,false+ PostgreSQL →true)_createactually passes[id]toinsertwhen the option is enabled, and[]when it is notFull package suite: 336 passing, 20 pending (
sqlite), pluseslintandprettierclean on the changed files.Docs
Added a short "RETURNING clause support" section to
docs/api/databases/knex.md, documenting thereturningknex option and the Firebird example.Other Information
Files changed:
packages/knex/src/adapter.ts,packages/knex/test/index.test.ts,docs/api/databases/knex.md(99 insertions, 2 deletions).