@@ -546,6 +546,16 @@ Serializes the database into a binary representation, returned as a
546546` Uint8Array ` . This is useful for saving, cloning, or transferring an in-memory
547547database. This method is a wrapper around [ ` sqlite3_serialize() ` ] [ ] .
548548
549+ ``` mjs
550+ import { DatabaseSync } from ' node:sqlite' ;
551+
552+ const db = new DatabaseSync (' :memory:' );
553+ db .exec (' CREATE TABLE t(key INTEGER PRIMARY KEY, value TEXT)' );
554+ db .exec (" INSERT INTO t VALUES (1, 'hello')" );
555+ const buffer = db .serialize ();
556+ console .log (buffer .length ); // Prints the byte length of the database
557+ ```
558+
549559``` cjs
550560const { DatabaseSync } = require (' node:sqlite' );
551561
@@ -574,6 +584,21 @@ are finalized before deserialization is attempted, even if the operation
574584subsequently fails. This method is a wrapper around
575585[ ` sqlite3_deserialize() ` ] [ ] .
576586
587+ ``` mjs
588+ import { DatabaseSync } from ' node:sqlite' ;
589+
590+ const original = new DatabaseSync (' :memory:' );
591+ original .exec (' CREATE TABLE t(key INTEGER PRIMARY KEY, value TEXT)' );
592+ original .exec (" INSERT INTO t VALUES (1, 'hello')" );
593+ const buffer = original .serialize ();
594+ original .close ();
595+
596+ const clone = new DatabaseSync (' :memory:' );
597+ clone .deserialize (buffer);
598+ console .log (clone .prepare (' SELECT value FROM t' ).get ());
599+ // Prints: { value: 'hello' }
600+ ```
601+
577602``` cjs
578603const { DatabaseSync } = require (' node:sqlite' );
579604
0 commit comments