I think nowadays you can do it with the backup function.
Information about backup (in C):
And looks like npm package sqlite3 exposed said api:
var db = new sqlite3.Database('live.db');
var backup = db.backup('backup.db');
...
// in event loop, move backup forward when we have time.
if (backup.idle) { backup.step(NPAGES); }
if (backup.completed) { ... success ... }
if (backup.failed) { ... sadness ... }
// do other work in event loop - fine to modify live.db
...
And from the C page looks like backup.step(-1);
will backup it all in one call.
I guess it is very useful if you create a :memory:
live database and backup/dump once in a while
Here is a similar answer link that suggest using "better-sqlite3"
db.backup(`my-backup.db`)
.then(() => {
console.log('backup complete!');
})
.catch((err) => {
console.log('backup failed:', err);
});