From 9aa0c1a4b021624226b78a064433f5704e920667 Mon Sep 17 00:00:00 2001 From: DjDeveloperr Date: Fri, 24 Feb 2023 18:50:02 +0530 Subject: [PATCH] fix(Database): do not set create: true if readonly is set to true (fix #93) --- src/database.ts | 2 +- test/test.ts | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/database.ts b/src/database.ts index 653e712..9149413 100644 --- a/src/database.ts +++ b/src/database.ts @@ -209,7 +209,7 @@ export class Database { flags |= SQLITE3_OPEN_READWRITE; } - if (options.create ?? true) { + if ((options.create ?? true) && !options.readonly) { flags |= SQLITE3_OPEN_CREATE; } } diff --git a/test/test.ts b/test/test.ts index 8e76b31..6a7be23 100644 --- a/test/test.ts +++ b/test/test.ts @@ -39,6 +39,11 @@ Deno.test("sqlite", async (t) => { Deno.removeSync("test-path.db"); }); + await t.step("open (readonly)", () => { + const db = new Database(":memory:", { readonly: true }); + db.close(); + }); + let db!: Database; await t.step("open (url)", () => { db = new Database(DB_URL, { int64: true });