fix(ext/node): implement SQLite Session API (#27909)

https://nodejs.org/api/sqlite.html#class-session

---------

Signed-off-by: Divy Srivastava <dj.srivastava23@gmail.com>
This commit is contained in:
Divy Srivastava 2025-02-04 21:59:13 +05:30 committed by GitHub
parent 98339cf327
commit 28834a89bb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 250 additions and 5 deletions

View file

@ -77,6 +77,27 @@ Deno.test("[node/sqlite] StatementSync read bigints are supported", () => {
assertEquals(stmt.expandedSQL, "SELECT * FROM data");
});
Deno.test("[node/sqlite] createSession and changesets", () => {
const db = new DatabaseSync(":memory:");
const session = db.createSession();
db.exec("CREATE TABLE test (id INTEGER PRIMARY KEY, name TEXT)");
db.exec("INSERT INTO test (name) VALUES ('foo')");
assert(session.changeset() instanceof Uint8Array);
assert(session.patchset() instanceof Uint8Array);
assert(session.changeset().byteLength > 0);
assert(session.patchset().byteLength > 0);
session.close();
// Use after close shoud throw.
assertThrows(() => session.changeset(), Error, "Session is already closed");
// Close after close should throw.
assertThrows(() => session.close(), Error, "Session is already closed");
});
Deno.test("[node/sqlite] StatementSync integer too large", () => {
const db = new DatabaseSync(":memory:");
db.exec("CREATE TABLE data(key INTEGER PRIMARY KEY);");