Skip to content

Commit

Permalink
add isClosed getter (#238)
Browse files Browse the repository at this point in the history
* add `isClosed` getter
* add tests and documentation to `isClosed` method
  • Loading branch information
adoublef authored Aug 20, 2023
1 parent ed24812 commit 243b218
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/db.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)");
Expand Down
8 changes: 8 additions & 0 deletions src/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

0 comments on commit 243b218

Please sign in to comment.