镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

sqlite: add serialize() and deserialize() to DatabaseSync #62575

Description

@thisalihassan

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?

  1. VACUUM INTO + fs.readFileSync: Requires disk I/O, a temp file path, and manual cleanup
  2. backup() API

Activity

  1. thisalihassan commented on Apr 3, 2026

    @thisalihassan
    ContributorAuthor

    I would like to work on this. sqlite3_serialize / sqlite3_deserialize are already compiled in so this is a matter of binding them.

    cc: @Renegade334 @geeksilva97 @ronag

  2. added
    sqliteIssues and PRs related to the SQLite subsystem.
    on Apr 3, 2026
  3. geeksilva97 commented on Apr 3, 2026

    @geeksilva97
    Contributor

    Go for it

  4. damianremington274-blip commented on Apr 3, 2026

    @damianremington274-blip
  5. thisalihassan commented on Apr 11, 2026

    @thisalihassan
    ContributorAuthor

    PR merged #62579 , closing issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestIssues requesting new Node.js features.sqliteIssues and PRs related to the SQLite subsystem.

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions