Exports
[<Class>]
type Exports =
static member constants: Constants6
static member DatabaseSync (path: PathLike, ?options: DatabaseSyncOptions) : DatabaseSync
static member backup (sourceDb: DatabaseSync, path: PathLike, ?options: BackupOptions) : Promise<float>| Assembly | Xantham.Fable.Node |
| Attributes | [<Erase>] |
The package's value exports, each bound to its import.
Properties
static member constants: Constants6
static member constants: Constants6@since v22.13.0
Methods
static member DatabaseSync (path: PathLike, ?options: DatabaseSyncOptions) : DatabaseSync
static member DatabaseSync (path: PathLike, ?options: DatabaseSyncOptions) : DatabaseSyncThis class represents a single connection to a SQLite database. All APIs exposed by this class execute synchronously.
@since v22.5.0
static member backup (sourceDb: DatabaseSync, path: PathLike, ?options: BackupOptions) : Promise<float>
static member backup (sourceDb: DatabaseSync, path: PathLike, ?options: BackupOptions) : Promise<float>This method makes a database backup. This method abstracts the sqlite3_backup_init(), sqlite3_backup_step() and sqlite3_backup_finish() functions.
The backed-up database can be used normally during the backup process. Mutations coming from the same connection - same DatabaseSync - object will be reflected in the backup right away. However, mutations from other connections will cause the backup process to restart.
import { backup, DatabaseSync } from 'node:sqlite';
const sourceDb = new DatabaseSync('source.db');
const totalPagesTransferred = await backup(sourceDb, 'backup.db', {
rate: 1, // Copy one page at a time.
progress: ({ totalPages, remainingPages }) => {
console.log('Backup in progress', { totalPages, remainingPages });
},
});
console.log('Backup completed', totalPagesTransferred);
@since v22.16.0
| Parameter | |
|---|---|
sourceDb | The database to backup. The source database must be open. |
path | The path where the backup will be created. If the file already exists, the contents will be overwritten. |
options | Optional configuration for the backup. The following properties are supported: |
Returns. A promise that fulfills with the total number of backed-up pages upon completion, or rejects if an error occurs.