| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -551,6 +551,63 @@ exception. | |||
| 551 | 551 | | `TEXT` | {string} | | |
| 552 | 552 | | `BLOB` | {TypedArray} or {DataView} | | |
| 553 | 553 | ||
| 554 | + ## `sqlite.backup(sourceDb, destination[, options])` | ||
| 555 | + | ||
| 556 | + <!-- YAML | ||
| 557 | + added: REPLACEME | ||
| 558 | + --> | ||
| 559 | + | ||
| 560 | + * `sourceDb` {DatabaseSync} The database to backup. The source database must be open. | ||
| 561 | + * `destination` {string} The path where the backup will be created. If the file already exists, the contents will be | ||
| 562 | + overwritten. | ||
| 563 | + * `options` {Object} Optional configuration for the backup. The | ||
| 564 | + following properties are supported: | ||
| 565 | + * `source` {string} Name of the source database. This can be `'main'` (the default primary database) or any other | ||
| 566 | + database that have been added with [`ATTACH DATABASE`][] **Default:** `'main'`. | ||
| 567 | + * `target` {string} Name of the target database. This can be `'main'` (the default primary database) or any other | ||
| 568 | + database that have been added with [`ATTACH DATABASE`][] **Default:** `'main'`. | ||
| 569 | + * `rate` {number} Number of pages to be transmitted in each batch of the backup. **Default:** `100`. | ||
| 570 | + * `progress` {Function} Callback function that will be called with the number of pages copied and the total number of | ||
| 571 | + pages. | ||
| 572 | + * Returns: {Promise} A promise that resolves when the backup is completed and rejects if an error occurs. | ||
| 573 | + | ||
| 574 | + This method makes a database backup. This method abstracts the [`sqlite3_backup_init()`][], [`sqlite3_backup_step()`][] | ||
| 575 | + and [`sqlite3_backup_finish()`][] functions. | ||
| 576 | + | ||
| 577 | + The backed-up database can be used normally during the backup process. Mutations coming from the same connection - same | ||
| 578 | + {DatabaseSync} - object will be reflected in the backup right away. However, mutations from other connections will cause | ||
| 579 | + the backup process to restart. | ||
| 580 | + | ||
| 581 | + ```cjs | ||
| 582 | + const { backup, DatabaseSync } = require('node:sqlite'); | ||
| 583 | + | ||
| 584 | + (async () => { | ||
| 585 | + const sourceDb = new DatabaseSync('source.db'); | ||
| 586 | + const totalPagesTransferred = await backup(sourceDb, 'backup.db', { | ||
| 587 | + rate: 1, // Copy one page at a time. | ||
| 588 | + progress: ({ totalPages, remainingPages }) => { | ||
| 589 | + console.log('Backup in progress', { totalPages, remainingPages }); | ||
| 590 | + }, | ||
| 591 | + }); | ||
| 592 | + | ||
| 593 | + console.log('Backup completed', totalPagesTransferred); | ||
| 594 | + })(); | ||
| 595 | + ``` | ||
| 596 | + | ||
| 597 | + ```mjs | ||
| 598 | + import { backup, DatabaseSync } from 'node:sqlite'; | ||
| 599 | + | ||
| 600 | + const sourceDb = new DatabaseSync('source.db'); | ||
| 601 | + const totalPagesTransferred = await backup(sourceDb, 'backup.db', { | ||
| 602 | + rate: 1, // Copy one page at a time. | ||
| 603 | + progress: ({ totalPages, remainingPages }) => { | ||
| 604 | + console.log('Backup in progress', { totalPages, remainingPages }); | ||
| 605 | + }, | ||
| 606 | + }); | ||
| 607 | + | ||
| 608 | + console.log('Backup completed', totalPagesTransferred); | ||
| 609 | + ``` | ||
| 610 | + | ||
| 554 | 611 | ## `sqlite.constants` | |
| 555 | 612 | ||
| 556 | 613 | <!-- YAML | |
@@ -632,6 +689,9 @@ resolution handler passed to [`database.applyChangeset()`][]. See also | |||
| 632 | 689 | [`SQLITE_DIRECTONLY`]: https://www.sqlite.org/c3ref/c_deterministic.html | |
| 633 | 690 | [`SQLITE_MAX_FUNCTION_ARG`]: https://www.sqlite.org/limits.html#max_function_arg | |
| 634 | 691 | [`database.applyChangeset()`]: #databaseapplychangesetchangeset-options | |
| 692 | + [`sqlite3_backup_finish()`]: https://www.sqlite.org/c3ref/backup_finish.html#sqlite3backupfinish | ||
| 693 | + [`sqlite3_backup_init()`]: https://www.sqlite.org/c3ref/backup_finish.html#sqlite3backupinit | ||
| 694 | + [`sqlite3_backup_step()`]: https://www.sqlite.org/c3ref/backup_finish.html#sqlite3backupstep | ||
| 635 | 695 | [`sqlite3_changes64()`]: https://www.sqlite.org/c3ref/changes.html | |
| 636 | 696 | [`sqlite3_close_v2()`]: https://www.sqlite.org/c3ref/close.html | |
| 637 | 697 | [`sqlite3_create_function_v2()`]: https://www.sqlite.org/c3ref/create_function.html | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -77,6 +77,7 @@ | |||
| 77 | 77 | V(asn1curve_string, "asn1Curve") \ | |
| 78 | 78 | V(async_ids_stack_string, "async_ids_stack") \ | |
| 79 | 79 | V(attributes_string, "attributes") \ | |
| 80 | + V(backup_string, "backup") \ | ||
| 80 | 81 | V(base_string, "base") \ | |
| 81 | 82 | V(bits_string, "bits") \ | |
| 82 | 83 | V(block_list_string, "blockList") \ | |
@@ -300,6 +301,7 @@ | |||
| 300 | 301 | V(primordials_string, "primordials") \ | |
| 301 | 302 | V(priority_string, "priority") \ | |
| 302 | 303 | V(process_string, "process") \ | |
| 304 | + V(progress_string, "progress") \ | ||
| 303 | 305 | V(promise_string, "promise") \ | |
| 304 | 306 | V(protocol_string, "protocol") \ | |
| 305 | 307 | V(prototype_string, "prototype") \ | |
@@ -314,6 +316,7 @@ | |||
| 314 | 316 | V(reason_string, "reason") \ | |
| 315 | 317 | V(refresh_string, "refresh") \ | |
| 316 | 318 | V(regexp_string, "regexp") \ | |
| 319 | + V(remaining_pages_string, "remainingPages") \ | ||
| 317 | 320 | V(rename_string, "rename") \ | |
| 318 | 321 | V(replacement_string, "replacement") \ | |
| 319 | 322 | V(required_module_facade_url_string, \ | |
@@ -367,6 +370,7 @@ | |||
| 367 | 370 | V(time_to_first_byte_sent_string, "timeToFirstByteSent") \ | |
| 368 | 371 | V(time_to_first_header_string, "timeToFirstHeader") \ | |
| 369 | 372 | V(tls_ticket_string, "tlsTicket") \ | |
| 373 | + V(total_pages_string, "totalPages") \ | ||
| 370 | 374 | V(transfer_string, "transfer") \ | |
| 371 | 375 | V(transfer_unsupported_type_str, \ | |
| 372 | 376 | "Cannot transfer object of unsupported type.") \ | |
| Back | FazBrowse Home | New Git URL |
0 commit comments