The backup() function in Node.js SQLite bindings currently has its TypeScript type defined as returning Promise<void>. However, the actual implementation returns an Promise<number> representing the number of pages backed up.
- Definition from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/node
https://github.com/DefinitelyTyped/DefinitelyTyped/blob/d65f24c95e732e4b0eadaebf63f5699801a05e59/types/node/v22/sqlite.d.ts#L639
- Example from nodejs docs https://nodejs.org/api/sqlite.html#sqlitebackupsourcedb-path-options
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);