Skip to content

Commit

Permalink
Fixed SQL-lite directory does not exist error
Browse files Browse the repository at this point in the history
  • Loading branch information
thehenrytsai committed Jan 11, 2024
1 parent 33b12b5 commit 7fcb9d3
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/storage.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import * as fs from 'fs';

import {
DataStoreLevel,
EventLogLevel,
Expand Down Expand Up @@ -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),
});
Expand Down

0 comments on commit 7fcb9d3

Please sign in to comment.