diff --git a/src/db.test.ts b/src/db.test.ts index 7f12cc0..824b703 100644 --- a/src/db.test.ts +++ b/src/db.test.ts @@ -215,6 +215,13 @@ Deno.test("close database", function () { db.close(); // check close is idempotent and won't throw }); +Deno.test("check database is closed", function () { + const db = new DB(); + assertEquals(db.isClosed, false); + db.close(); + assertEquals(db.isClosed, true); +}); + Deno.test("open queries block close", function () { const db = new DB(); db.query("CREATE TABLE test (name TEXT PRIMARY KEY)"); diff --git a/src/db.ts b/src/db.ts index dee79f5..770884b 100644 --- a/src/db.ts +++ b/src/db.ts @@ -737,4 +737,12 @@ export class DB { get autoCommit(): boolean { return this.#wasm.autocommit() !== 0; } + + /** + * Returns `true` when the database handle is closed + * and can no longer be used. + */ + get isClosed(): boolean { + return !this.#open; + } }