From 7fcb9d356969a8632c9aa0ad891be2b55cca054a Mon Sep 17 00:00:00 2001 From: Henry Tsai Date: Thu, 11 Jan 2024 14:50:38 -0800 Subject: [PATCH] Fixed SQL-lite directory does not exist error --- src/storage.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/storage.ts b/src/storage.ts index d8c8642..1b051f9 100644 --- a/src/storage.ts +++ b/src/storage.ts @@ -1,3 +1,5 @@ +import * as fs from 'fs'; + import { DataStoreLevel, EventLogLevel, @@ -128,7 +130,13 @@ export function getDialectFromURI(u: URL): Dialect { switch (u.protocol.slice(0, -1)) { case BackendTypes.SQLITE: const path = u.host + u.pathname; - console.log('Relative SQL-lite path:', path); + console.log('SQL-lite relative path:', path ? path : undefined); // NOTE, using ? for lose equality comparison + + if (u.host && !fs.existsSync(u.host)) { + console.log('SQL-lite directory does not exist, creating:', u.host); + fs.mkdirSync(u.host, { recursive: true }); + } + return new SqliteDialect({ database: async () => new Database(path), });