What is the problem this feature will solve?
There is currently no way to extract a database's contents as a binary buffer or load a database from one. Users may use this for snapshot, clone, transfer, etc. Popular libraries like better-sqlite3 expose db.serialize() and new Database(buffer) for this purpose.
What is the feature you are proposing to solve the problem?
Add serialize() and deserialize() methods to DatabaseSync:
const { DatabaseSync } = require('node:sqlite');
// serialize: returns the database as a Uint8Array
const db = new DatabaseSync(':memory:');
db.exec("CREATE TABLE t(x TEXT)");
db.exec("INSERT INTO t VALUES ('hello')");
const buffer = db.serialize(); // Uint8Array
// deserialize: loads a buffer into the connection, replacing the current database
const db2 = new DatabaseSync(':memory:');
db2.deserialize(buffer);
db2.prepare('SELECT * FROM t').get(); // { x: 'hello' }
What alternatives have you considered?
- VACUUM INTO + fs.readFileSync: Requires disk I/O, a temp file path, and manual cleanup
- backup() API
What is the problem this feature will solve?
There is currently no way to extract a database's contents as a binary buffer or load a database from one. Users may use this for snapshot, clone, transfer, etc. Popular libraries like
better-sqlite3exposedb.serialize()andnew Database(buffer)for this purpose.What is the feature you are proposing to solve the problem?
Add serialize() and deserialize() methods to DatabaseSync:
What alternatives have you considered?