method
sqlite.DatabaseSync.serialize
dbName?: string
): NonSharedUint8Array;
Serializes the database into a binary representation, returned as a Uint8Array. This is useful for saving, cloning, or transferring an in-memory database. This method is a wrapper around sqlite3_serialize().
import { DatabaseSync } from 'node:sqlite';
const db = new DatabaseSync(':memory:');
db.exec('CREATE TABLE t(key INTEGER PRIMARY KEY, value TEXT)');
db.exec("INSERT INTO t VALUES (1, 'hello')");
const buffer = db.serialize();
console.log(buffer.length); // Prints the byte length of the database@param dbName
Name of the database to serialize. This can be 'main' (the default primary database) or any other database that has been added with ATTACH DATABASE. Default: 'main'.
@returns
A binary representation of the database.