-
Notifications
You must be signed in to change notification settings - Fork 30.3k
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: expose backup api #56253
base: main
Are you sure you want to change the base?
sqlite: expose backup api #56253
Conversation
6c61b4c
to
9b80c2d
Compare
632edd3
to
174ace5
Compare
174ace5
to
2aee11d
Compare
This comment mentions that The backup can be performed synchronously but I don't think it should be like that. I wonder if indeed this PR would be more suitable for async API. Any thoughts? Thanks in advance |
69a3bf3
to
bd43083
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #56253 +/- ##
==========================================
+ Coverage 89.18% 89.20% +0.02%
==========================================
Files 662 662
Lines 191759 192100 +341
Branches 36911 36979 +68
==========================================
+ Hits 171017 171362 +345
+ Misses 13613 13558 -55
- Partials 7129 7180 +51
|
Hi hi @cjihrig . Could you share your thoughts? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't made it through the changes in src/node_sqlite.cc
yet, but left some comments. This also needs docs before landing.
371f368
to
a92e692
Compare
a92e692
to
fa23c05
Compare
9069aa8
to
fa23c05
Compare
Failing test seems unrelated |
8e2caea
to
c532c58
Compare
That is not a requirement. |
@@ -115,6 +115,26 @@ added: v22.5.0 | |||
|
|||
Constructs a new `DatabaseSync` instance. | |||
|
|||
### `database.backup(destination[, options])` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not something that needs to happen in this PR necessarily, but we will need to rename the DatabaseSync
class now that an async operation is being added. My plan was always to keep the sync and async APIs separated, similar to the fs module. Since we are breaking from that, I'll leave it up to others to decide on naming, keeping in mind that there is already a feature request for an async API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it could be a start for that async API.
I asked about this in the issue but I didn't get an answer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question, @cjihrig . In your plans, would DatabaseSync have a backup feature?
Personally, I have no problem moving this to a Database
class (without the Sync
) as a start for that async API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it need to be a method on DatabaseSync
? Could it be a separate API exposed on the node:sqlite
module? e.g.
const { backup, DatabaseSync } = require('node:sqlite');
const db = new DatabaseSync(...);
// ...
await backup(db);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this idea!
Closes #55413
This PR exposes the SQLite Online Backup API, which allows database backup.
The API is inspired by better-sqlite3 https://github.com/WiseLibs/better-sqlite3/blob/master/docs/api.md#backupdestination-options---promise.
Multithreading caveats
As long as writes come from the same process and handle (
sqlite*
), the backup will continue progressing as expected. Other than that, it can cause the backup process to restart. From docs: