Skip to content

Commit

Permalink
fix(Database): do not set create: true if readonly is set to true (fix
Browse files Browse the repository at this point in the history
  • Loading branch information
DjDeveloperr committed Feb 24, 2023
1 parent 4cb7e8f commit 9aa0c1a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
5 changes: 5 additions & 0 deletions test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down

0 comments on commit 9aa0c1a

Please sign in to comment.