-
Notifications
You must be signed in to change notification settings - Fork 30.4k
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
Changes from all commits
666034f
c73a3cc
5ad3f48
a050cd6
9d8538b
4abb1b2
74a9ad4
d58fd03
e3e7431
acec23e
fa23c05
c532c58
0df678e
7b15cae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -523,6 +523,27 @@ exception. | |
| `TEXT` | {string} | | ||
| `BLOB` | {Uint8Array} | | ||
|
||
## `sqlite.backup(sourceDb, destination[, options])` | ||
|
||
<!-- YAML | ||
added: REPLACEME | ||
--> | ||
|
||
* `sourceDb` {DatabaseSync} The database to backup. The source database must be open. | ||
* `destination` {string} The path where the backup will be created. If the file already exists, the contents will be | ||
jasnell marked this conversation as resolved.
Show resolved
Hide resolved
|
||
overwritten. | ||
* `options` {Object} Optional configuration for the backup. The | ||
following properties are supported: | ||
* `source` {string} Name of the source database. **Default:** `'main'`. | ||
* `target` {string} Name of the target database. **Default:** `'main'`. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For users who may not be that familiar with things here, the docs could likely benefit from more explanation about how |
||
* `rate` {number} Number of pages to be transmitted in each batch of the backup. **Default:** `100`. | ||
* `progress` {Function} Callback function that will be called with the number of pages copied and the total number of | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not something that needs to be added in this PR but... would it make sense for this operation to support cancelation via an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 |
||
pages. | ||
* Returns: {Promise} A promise that resolves when the backup is completed and rejects if an error occurs. | ||
|
||
This method makes a database backup. This method abstracts the [`sqlite3_backup_init()`][], [`sqlite3_backup_step()`][] | ||
and [`sqlite3_backup_finish()`][] functions. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since the backup operation is async and may take some time, some discussion in here about concurrent edits while the db is being backed up would be helpful for users to understand what to expect. |
||
|
||
## `sqlite.constants` | ||
|
||
<!-- YAML | ||
|
@@ -604,6 +625,9 @@ resolution handler passed to [`database.applyChangeset()`][]. See also | |
[`SQLITE_DETERMINISTIC`]: https://www.sqlite.org/c3ref/c_deterministic.html | ||
[`SQLITE_DIRECTONLY`]: https://www.sqlite.org/c3ref/c_deterministic.html | ||
[`database.applyChangeset()`]: #databaseapplychangesetchangeset-options | ||
[`sqlite3_backup_finish()`]: https://www.sqlite.org/c3ref/backup_finish.html#sqlite3backupfinish | ||
[`sqlite3_backup_init()`]: https://www.sqlite.org/c3ref/backup_finish.html#sqlite3backupinit | ||
[`sqlite3_backup_step()`]: https://www.sqlite.org/c3ref/backup_finish.html#sqlite3backupstep | ||
[`sqlite3_changes64()`]: https://www.sqlite.org/c3ref/changes.html | ||
[`sqlite3_close_v2()`]: https://www.sqlite.org/c3ref/close.html | ||
[`sqlite3_create_function_v2()`]: https://www.sqlite.org/c3ref/create_function.html | ||
|
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.
If this is assumed to be a filesystem path, then handling it the same as our other fs APIs would be ideal. Paths can be expressed as either strings,
Buffer
, orfile://
scheme URLs. If you're not familiar, there are internal utilities for normalizing these into a usable path.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.
Makes sense. I will search for examples to see how to do that.
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.
Maybe that? https://github.com/nodejs/node/blob/main/lib/internal/fs/utils.js#L700-L720