Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #5769: Sqlite support multi-value JSON insert #5782

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

code-ape
Copy link
Collaborator

@code-ape code-ape commented Dec 29, 2023

Issues:

  1. Sqlite multi-insert fails to convert Object to JSON string but does for single insert #5769

Changes:

  1. Added version utility functions for easily parsing and validating version comparisons, via lib/util/version.ts.
  2. Added thorough testing for above version utility functions, via test/unit/util/version.js.
  3. Updated sqlite3 client to support getting parsed client version and validating it against min and max version, via lib/dialects/sqlite3/index.js.
  4. Updated better-sqlite3 client with known safe default client version and opened issue for getting it in the future, via lib/dialects/better-sqlite3/index.js.
  5. Updated base client logic to not re-initialize driver if it is already initialized, via lib/client.js.
  6. Updated sqlite3 insert query compiler to use "standard" SQL syntax instead of "select union all" pattern as it has not been needed for over a decade now since sqlite3 3.7.11 with error thrown on multi-inserts if sqlite3 client is found to be older than that version, via lib/dialects/sqlite3/query/sqlite-querycompiler.js.
  7. Added tests for issue Sqlite multi-insert fails to convert Object to JSON string but does for single insert #5769 to validate multi-json insert works and client version check works, via test/integration2/query/insert/inserts.spec.js.
  8. Fixed various broken tests related to sqlite3 from above changes, via test/.

@code-ape code-ape self-assigned this Dec 29, 2023
@coveralls
Copy link

coveralls commented Dec 29, 2023

Coverage Status

coverage: 92.8% (+0.01%) from 92.787%
when pulling 5db4d79 on code-ape:issue-5769/sqlite-multi-json
into 4ca3dd5 on knex:master.

@code-ape code-ape marked this pull request as ready for review December 30, 2023 19:23

# Do not include .js files from .ts files
util/version.js
dialects/index.js
Copy link
Collaborator

@kibertoad kibertoad Jan 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this causes files not to be published either, I'd rather have them committed

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohhhh! Good to know. There's a script generating these .gitignore items . I can update it stop doing that and check in the generated code.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's ok to generate them prepublish too, to protect against someone forgetting to run it

returning,
};
if (
!this.client._satisfiesVersion([3, 7, 11]) &&
Copy link
Collaborator

@kibertoad kibertoad Jan 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather do this check once on driver instantiation and set a feature boolean flag for subsequent checks

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kibertoad what do you want to do if we initialize with the driver with a version below the 3.7.11 threshold? Throw an error and halt, forcing at least that version? Something else?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it break anyway if someone attempts a multi-value JSON insert anyway? Do we need to force-break anything?

// and better-sqlite3 1.0.0 shipped with 3.25.1 in 2016.
//
// Issue opened for this: https://github.com/WiseLibs/better-sqlite3/issues/1122
return [3, 25, 1];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we require minimum better-sqlite with support for multi-insert via peerDependencies? I'd rather force people to upgrade rather than lock out them out of the beneficial feature

Copy link
Collaborator Author

@code-ape code-ape Jan 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, two thoughts:

  1. If better-sqlite3 users are using the bundled sqlite3 build then they're fine. The 1.0.0 version of better-sqlite3 satisfies the 10+ year old requirement of being at least 3.11.7.
  2. Technically the users of better-sqlite3 (and sqlite3 for that matter) can use a different C compilation of the sqlite3 library. So the NPM package version doesn't guarantee the version of sqlite3.c they've compiled.

What would you like to do?

PS - I've opened a PR to better-sqlite3 to fix this: WiseLibs/better-sqlite3#1124

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After WiseLibs/better-sqlite3#1124 is merged we can do a more explicit check, but for older versions I would let user proceed by default and let them crash if their version is too old.


describe(`#5769 sqlite multi-insert uses standard syntax and supports JSON (does NOT include better-sqlite3)`, function () {
it(`should JSON.stringify Sqlite multi-insert of Objects`, async function () {
if (!isSQLite3(knex)) {
Copy link
Collaborator

@kibertoad kibertoad Jan 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does newer better-sqlite support this feature?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll update the test and check. I think so, when I was originally authoring this I was just trying to focus on making sure that sqlite3 worked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants