-
-
Notifications
You must be signed in to change notification settings - Fork 34.2k
SQLite Async API #59109
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
base: main
Are you sure you want to change the base?
SQLite Async API #59109
Conversation
|
Review requested:
|
Concurrency ControlFor concurrency control, SQLite provides a few options. Multi-threaded seems to be a good fit.
We just need a way to guarantee that no two threads will be using |
I wonder if, for the first version of this API if the
|
ac01d39 to
ed659be
Compare
dbf9d40 to
4ffdccf
Compare
6561e49 to
9af39ec
Compare
9af39ec to
ed24a9b
Compare
ed24a9b to
710f3b5
Compare
4bf5609 to
8ce4e74
Compare
8ce4e74 to
081d7c5
Compare
e46021e to
5e6d3a2
Compare
5e6d3a2 to
7acd4eb
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #59109 +/- ##
==========================================
- Coverage 88.54% 88.50% -0.05%
==========================================
Files 703 703
Lines 208291 208690 +399
Branches 40170 40244 +74
==========================================
+ Hits 184430 184691 +261
- Misses 15865 15961 +96
- Partials 7996 8038 +42
🚀 New features to boost your workflow:
|
|
It turns out I was very naive while conceiving this implementation. My approach was to utilize libuv's thread pool for running SQLite operations, as we do for backups. In a situation where a query calls a user-defined function, authorizer, or aggregation, execution on the thread pool fails because it doesn't have access to an Isolate. My first idea was to track the defined functions and identify when they are in the query; if functions are present, that query would run in the main thread. Another option would be using worker threads that have their own isolates. @nodejs/sqlite would you have any clue? Thanks in advance. |
better-sqlite lets the developer decide, suggesting worker threads https://github.com/WiseLibs/better-sqlite3/blob/master/docs/threads.md |
69cb3ab to
5bec78e
Compare
|
I would consider not adding any async APIs, and instead
The overhead of serializing queries and results probably makes this somewhat of an advanced use case. Defaulting to async for all queries is (probably) a mistake for most applications. Instead it is something you might do for a few expensive queries. I could be wrong though. |
From the beginning, the idea is not to default all queries to run asynchronously. It's about to add the possibility for async. Like fs and fs/promises |
|
having implemented worker thread offloading i can state that there's a significant amount of gnarly lifecycle plumbing involved, especially if one wants to support transactions |
Yeah. I will build a solution based on the authorizer, and let's see what you think about it. |
I think the API should reflect this. If it is named Maybe calling it something like Or maybe |
Closes #54307
This PR implements an async API for
node:sqlitemodule. So far, it contains a very minimal implementation ofexecmethod, misses some tests, docs and refactoring but it is good enough to share the whole theory I have for it; with that, anybody can share thoughts about it.Design
On C++ land, I plan to have the
Databaseclass determine whether the operations will be asynchronous.Public API
For the public API, I plan to have classes such as
Database,Statement, etc., as counterparts to' DatabaseSync', ' StatementSync', and so on.