-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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
sqlite: add support for SQLite Session Extension #54181
Conversation
Review requested:
|
Wouldn't this be solved if users could use their own SQLite build? That's already being considered according to the original issue. |
@karimfromjordan Nope, because you need access to the C API to access this feature. |
Can you add the appropriate documentation as well? |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #54181 +/- ##
==========================================
+ Coverage 88.40% 88.41% +0.01%
==========================================
Files 654 654
Lines 187594 188034 +440
Branches 36089 36169 +80
==========================================
+ Hits 165834 166259 +425
+ Misses 15001 14999 -2
- Partials 6759 6776 +17
|
I need to make sure sessions are deleted before the database they are attached to is closed. I think I need the When a |
9fe44b8
to
36e1920
Compare
@anonrig I have added documentation, most of the functionality and fixed the lint issues. Could you trigger another CI run? I want to add support for generating a patchset and then this PR is ready for review. I have some ideas for future improvements, e.g. more fine-grained conflict handling or exposing the utilities SQLite provides for inspecting and merging changesets, but they can be added in a backward-compatible manner. |
768d950
to
1948ee0
Compare
8fc1cf0
to
aaf0928
Compare
08b3562
to
b544d2f
Compare
This is excellent work that many projects will surely be based on. I am curious about the eventual wrapping of the entire Sessions C API (mixed & mashed into higher-level Node functions). Does this PR leave space for that? There are a few more Sessions API functions that would be of great use in Node. |
@TheOneTheOnlyJJ Thanks! I agree that exposing more functionality of the Session Extension in Node.js would be great. Here are some ideas:
Here is the full API for future reference: https://www.sqlite.org/session/funclist.html Right now I first want to gather some feedback, but I'd be interested continue working on this, either in a follow-up PR or in this one. Since the SQLite integration is still under active development I think working incrementally is the preferred approach. |
Good point, here's my view on them:
Yes, I was about to suggest these. There's also
This should be a high priority right now, as long-running Node processes (like server back-ends) that would use Sessions will have their memory slowly but surely filled up with no way of freeing it without closing the database connection. Applications could run for months or even longer without closing a database connection, so not being able to close Sessions and free their memory would deter developers from using them. The database should, of course, still keep a list of all active sessions and delete them when it is closed, just in case not all Sessions were manually closed. From my point of view, this function should be wrapped as soon as possible and be included in this PR. Not having it surely decreases the chances of getting this merged, and it would be a shame to lose out on this.
Very important functionalities, but again, they're not vital for achieving functional basic interaction with the extension. These 3 points could be bundled in a follow-up PR that handles the finer-grained data management side of the API. The
I've noticed this in the documentation and it's definitely a part of the API that would be crucial in large apps with large databases. But again, for the current goal of incrementally proposing a stable API that exposes the API of the extension, this is not required right now. It would also require wrapping Also, before I wrap up... I noticed that you proposed the |
Agreed. I will still add this one as part of this PR.
I don't see any benefits. Furthermore, I like the philosophy of better-sqlite3:
In this vein I also oped to default to aborting on conflict, instead of requiring an explicit conflict handler to be passed like in the API of SQLite. |
Yes, this would be ideal. For further updates other than this, I believe it's best to wait for the final form of the
I was checking if any additional functionality could be squeezed out by separating the functions. Given that there is none, your decision is a sensible one and I support it.
This is also the best sane default option, as every developer should customize this behavior according to their use case. I'm not experienced in the internals of Node, so my contribution here can only amount to discussing the API design and smaller implementation details. I guess the next step now (after implementing the Session |
Happy to see that CI is green! I made one more small fix to address a PR comment from @jasnell to include strings in the environment. Let me know if there's anything else. 🙏 |
Commit Queue failed- Loading data for nodejs/node/pull/54181 ✔ Done loading data for nodejs/node/pull/54181 ----------------------------------- PR info ------------------------------------ Title sqlite: add support for SQLite Session Extension (#54181) ⚠ Could not retrieve the email or name of the PR author's from user's GitHub profile! Branch louwers:session-extension -> nodejs:main Labels c++, lib / src, author ready, sqlite Commits 31 - sqlite: add support for SQLite Session Extension - doc: address PR comment @RedYetiDev - sqlite: keep MemoryInfo related stuff together - sqlite: use snake_case for local variables - sqlite: remove unneccesary use of node namespace - sqlite: improve working filter parameter - sqlite: add comment about using static functions - doc: improve wording default value onConflict - doc: capitalize Default - doc: improve wording options documentation - doc: improve options documentation - doc: improve wording table parameter - test: improve test name - sqlite: move SQLITE_ENABLE_SESSION to node.gyp - test: split out sqlite session test and fix null __proto__ - sqlite: use FIXED_ONE_BYTE_STRING instead of NewFromUtf8 - sqlite: don't use ToLocalChecked - sqlite: avoid double check - doc: add documentation for constants - doc: add explanation database name - test: remove unused imports test-sqlite.js - test: add some extra asserts for changeset and patchset - test: create suite for conflict resolution - test: fix deepStrictEqual helper - test: fix lint issues - doc: fix lint issue - test: format import - sqlite: run format - sqlite: add filter and onConflict to env_properties.h - sqlite: format - sqlite: simplify string conversion Committers 2 - Bart Louwers <bart@emeel.net> - GitHub <noreply@github.com> PR-URL: https://github.com/nodejs/node/pull/54181 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> ------------------------------ Generated metadata ------------------------------ PR-URL: https://github.com/nodejs/node/pull/54181 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> -------------------------------------------------------------------------------- ℹ This PR was created on Fri, 02 Aug 2024 17:57:31 GMT ✔ Approvals: 3 ✔ - Yagiz Nizipli (@anonrig) (TSC): https://github.com/nodejs/node/pull/54181#pullrequestreview-2217182204 ✔ - James M Snell (@jasnell) (TSC): https://github.com/nodejs/node/pull/54181#pullrequestreview-2417021902 ✔ - Colin Ihrig (@cjihrig): https://github.com/nodejs/node/pull/54181#pullrequestreview-2441289456 ✔ Last GitHub CI successful ℹ Last Full PR CI on 2024-11-17T14:29:53Z: https://ci.nodejs.org/job/node-test-pull-request/63603/ - Querying data for job/node-test-pull-request/63603/ ✔ Last Jenkins CI successful -------------------------------------------------------------------------------- ✔ No git cherry-pick in progress ✔ No git am in progress ✔ No git rebase in progress -------------------------------------------------------------------------------- - Bringing origin/main up to date... From https://github.com/nodejs/node * branch main -> FETCH_HEAD ✔ origin/main is now up-to-date - Downloading patch for 54181 From https://github.com/nodejs/node * branch refs/pull/54181/merge -> FETCH_HEAD ✔ Fetched commits as d159c9732022..092a28c38383 -------------------------------------------------------------------------------- Auto-merging doc/api/sqlite.md Auto-merging src/env_properties.h Auto-merging src/node_sqlite.cc [main ebd8540f5e] sqlite: add support for SQLite Session Extension Author: Bart Louwers <bart@emeel.net> Date: Sat Nov 2 19:17:33 2024 +0100 7 files changed, 766 insertions(+), 18 deletions(-) Auto-merging doc/api/sqlite.md [main c5f293f53d] doc: address PR comment @RedYetiDev Author: Bart Louwers <bart@emeel.net> Date: Sat Nov 2 19:21:26 2024 +0100 1 file changed, 8 insertions(+), 10 deletions(-) [main 2fa11850c2] sqlite: keep MemoryInfo related stuff together Author: Bart Louwers <bart.louwers@gmail.com> Date: Sat Nov 2 19:24:26 2024 +0100 1 file changed, 1 insertion(+), 1 deletion(-) Auto-merging src/node_sqlite.cc [main 2947d277f7] sqlite: use snake_case for local variables Author: Bart Louwers <bart@emeel.net> Date: Sat Nov 2 19:27:58 2024 +0100 1 file changed, 3 insertions(+), 3 deletions(-) Auto-merging src/node_sqlite.cc [main f2b2725274] sqlite: remove unneccesary use of node namespace Author: Bart Louwers <bart@emeel.net> Date: Sat Nov 2 19:38:17 2024 +0100 1 file changed, 36 insertions(+), 38 deletions(-) Auto-merging doc/api/sqlite.md [main 899ca75f64] sqlite: improve working filter parameter Author: Bart Louwers <bart.louwers@gmail.com> Date: Sat Nov 2 19:53:16 2024 +0100 1 file changed, 1 insertion(+), 3 deletions(-) Auto-merging src/node_sqlite.cc [main 44551c1a35] sqlite: add comment about using static functions Author: Bart Louwers <bart@emeel.net> Date: Sat Nov 2 19:41:34 2024 +0100 1 file changed, 2 insertions(+) Auto-merging doc/api/sqlite.md [main 48db7181a8] doc: improve wording default value onConflict Author: Bart Louwers <bart@emeel.net> Date: Sat Nov 2 19:56:08 2024 +0100 1 file changed, 2 insertions(+), 2 deletions(-) Auto-merging doc/api/sqlite.md [main 21b060895c] doc: capitalize Default Author: Bart Louwers <bart@emeel.net> Date: Sat Nov 2 19:57:27 2024 +0100 1 file changed, 2 insertions(+), 2 deletions(-) Auto-merging doc/api/sqlite.md [main 290de00f82] doc: improve wording options documentation Author: Bart Louwers <bart.louwers@gmail.com> Date: Sat Nov 2 19:57:53 2024 +0100 1 file changed, 1 insertion(+), 1 deletion(-) Auto-merging doc/api/sqlite.md [main 83958e87e8] doc: improve options documentation Author: Bart Louwers <bart.louwers@gmail.com> Date: Sat Nov 2 19:58:48 2024 +0100 1 file changed, 1 insertion(+), 1 deletion(-) Auto-merging doc/api/sqlite.md [main 913d312858] doc: improve wording table parameter Author: Bart Louwers <bart.louwers@gmail.com> Date: Sat Nov 2 19:59:45 2024 +0100 1 file changed, 1 insertion(+), 2 deletions(-) [main 2d2aa297b6] test: improve test name Author: Bart Louwers <bart.louwers@gmail.com> Date: Sat Nov 2 20:00:12 2024 +0100 1 file changed, 1 insertion(+), 1 deletion(-) [main ceb4a8951a] sqlite: move SQLITE_ENABLE_SESSION to node.gyp Author: Bart Louwers <bart@emeel.net> Date: Sat Nov 2 22:01:38 2024 +0100 2 files changed, 1 insertion(+), 2 deletions(-) [main 6a7a3bca38] test: split out sqlite session test and fix null __proto__ Author: Bart Louwers <bart@emeel.net> Date: Sat Nov 2 22:28:23 2024 +0100 2 files changed, 368 insertions(+), 350 deletions(-) create mode 100644 test/parallel/test-sqlite-session.js Auto-merging src/node_sqlite.cc [main c785a23532] sqlite: use FIXED_ONE_BYTE_STRING instead of NewFromUtf8 Author: Bart Louwers <bart@emeel.net> Date: Sat Nov 2 22:50:35 2024 +0100 1 file changed, 1 insertion(+), 3 deletions(-) Auto-merging src/node_sqlite.cc [main 9af718ebbb] sqlite: don't use ToLocalChecked Author: Bart Louwers <bart@emeel.net> Date: Sat Nov 2 22:52:16 2024 +0100 1 file changed, 4 insertions(+), 2 deletions(-) Auto-merging src/node_sqlite.cc [main e270f8d95d] sqlite: avoid double check Author: Bart Louwers <bart@emeel.net> Date: Sat Nov 2 23:18:02 2024 +0100 1 file changed, 2 insertions(+), 3 deletions(-) Auto-merging doc/api/sqlite.md [main 74f7d3d073] doc: add documentation for constants Author: Bart Louwers <bart@emeel.net> Date: Sat Nov 2 23:43:50 2024 +0100 1 file changed, 29 insertions(+) Auto-merging doc/api/sqlite.md [main c77de92d83] doc: add explanation database name Author: Bart Louwers <bart@emeel.net> Date: Sat Nov 2 23:49:52 2024 +0100 1 file changed, 3 insertions(+), 1 deletion(-) [main 4f405293b2] test: remove unused imports test-sqlite.js Author: Bart Louwers <bart@emeel.net> Date: Sat Nov 2 23:50:14 2024 +0100 1 file changed, 3 deletions(-) [main 266d848a22] test: add some extra asserts for changeset and patchset Author: Bart Louwers <bart@emeel.net> Date: Sat Nov 2 23:53:47 2024 +0100 1 file changed, 10 insertions(+), 1 deletion(-) [main d78df860a6] test: create suite for conflict resolution Author: Bart Louwers <bart@emeel.net> Date: Sat Nov 2 23:58:35 2024 +0100 1 file changed, 66 insertions(+), 64 deletions(-) [main 6cbc255471] test: fix deepStrictEqual helper Author: Bart Louwers <bart@emeel.net> Date: Sun Nov 3 00:08:41 2024 +0100 1 file changed, 7 insertions(+), 1 deletion(-) [main 27092f6cc6] test: fix lint issues Author: Bart Louwers <bart@emeel.net> Date: Sun Nov 3 00:10:41 2024 +0100 1 file changed, 9 insertions(+), 10 deletions(-) Auto-merging doc/api/sqlite.md [main 0504b8f830] doc: fix lint issue Author: Bart Louwers <bart@emeel.net> Date: Sun Nov 3 00:11:11 2024 +0100 1 file changed, 2 insertions(+), 2 deletions(-) [main 0aaae4a9c2] test: format import Author: Bart Louwers <bart@emeel.net> Date: Sun Nov 3 00:13:37 2024 +0100 1 file changed, 1 insertion(+), 3 deletions(-) Auto-merging src/node_sqlite.cc [main 76f79b0164] sqlite: run format Author: Bart Louwers <bart@emeel.net> Date: Sat Nov 16 18:31:57 2024 +0100 1 file changed, 3 insertions(+), 2 deletions(-) Auto-merging src/env_properties.h Auto-merging src/node_sqlite.cc [main b464b1f628] sqlite: add filter and onConflict to env_properties.h Author: Bart Louwers <bart@emeel.net> Date: Sun Nov 17 02:58:21 2024 +0100 2 files changed, 5 insertions(+), 12 deletions(-) Auto-merging src/node_sqlite.cc [main 03979904cc] sqlite: format Author: Bart Louwers <bart@emeel.net> Date: Sun Nov 17 02:58:48 2024 +0100 1 file changed, 2 insertions(+), 1 deletion(-) Auto-merging src/node_sqlite.cc [main 81c2d95b72] sqlite: simplify string conversion Author: Bart Louwers <bart@emeel.net> Date: Sun Nov 17 03:09:00 2024 +0100 1 file changed, 1 insertion(+), 1 deletion(-) ✔ Patches applied There are 31 commits in the PR. Attempting autorebase. Rebasing (2/62) Executing: git node land --amend --yes --------------------------------- New Message ---------------------------------- sqlite: add support for SQLite Session Extensionhttps://github.com/nodejs/node/actions/runs/11883643605 |
Landed in 746b17e |
Congratulations @louwers! This will open up great opportunities for developers! But now, what are the next steps? There are quite a few functions left in the API with no wrapper, besides the more complicated async stuff. Should this discussion move to a new issue? |
@TheOneTheOnlyJJ Thank you, I hope so. Sure, I have some ideas for follow-up work. What would be your priority? I will create an issue this week. |
Your ideas are solid. It makes sense to pursue them as you mentioned. Maybe the rest of the simpler features could be implemented first, as they would expose more API area of the extension But as an even greater priority, I believe we should create a table that maps the C API of the extension to the Node API implemented up to date directly, with "Not implemented" noted where there's no Node equivalent for the native C API yet (functions, constants, etc.). I believe this would:
Also, if included in the official documentation, this table would:
|
PR-URL: #54181 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
We were talking about adding support for the Session Extension of SQLite in #53752. This is not a run-time extension but rather a feature built in to the SQLite amalgamation. It can be enabled with a compile flag and is enabled by default on some platforms.
I have never contributed to Node.js before so I will probably need some help to bring this to a conclusion.
TODO:
Throw with specific (documented) exception in case of conflict when applying changesetsince SQLite doesn't consider this to be an error I returnfalse
when applying the changeset is aborted due to a conflictExample usage: