-
-
Notifications
You must be signed in to change notification settings - Fork 35.2k
sqlite: add serialize() and deserialize() to DatabaseSync #62575
Copy link
Copy link
Open
Labels
feature requestIssues that request new features to be added to Node.js.Issues that request new features to be added to Node.js.sqliteIssues and PRs related to the SQLite subsystem.Issues and PRs related to the SQLite subsystem.
Description
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
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
feature requestIssues that request new features to be added to Node.js.Issues that request new features to be added to Node.js.sqliteIssues and PRs related to the SQLite subsystem.Issues and PRs related to the SQLite subsystem.
Type
Projects
Status
Awaiting Triage