From 5114a7f3be7292a132b4f5e78704752158c17238 Mon Sep 17 00:00:00 2001 From: Andrey Lushnikov Date: Sun, 19 Nov 2023 00:17:46 -0800 Subject: [PATCH] fix: support passing file:// URI when SQLite was compiled with `SQLITE_USE_URI=1` I'm trying to use `better-sqlite3` with an SQLite that is compiled with `SQLITE_USE_URI=1`: ```js const db = SQLite(`file:///foo/bar?vfs=myfs&mode=ro&immutable=1`); ``` This, however, doesn't work right now, since there's an erroneous assertion in the database creation. With this patch, I can successfully connect to database. References https://github.com/WiseLibs/better-sqlite3/issues/483 --- lib/database.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/database.js b/lib/database.js index 14e05739..39b3cb38 100644 --- a/lib/database.js +++ b/lib/database.js @@ -61,7 +61,7 @@ function Database(filenameGiven, options) { } // Make sure the specified directory exists - if (!anonymous && !fs.existsSync(path.dirname(filename))) { + if (!filename.startsWith('file://') && !anonymous && !fs.existsSync(path.dirname(filename))) { throw new TypeError('Cannot open database because the directory does not exist'); }