Skip to content

Commit

Permalink
fix(sqlite): error msg when parent folder doesn't exist (#104)
Browse files Browse the repository at this point in the history
Co-authored-by: Shigma <shigma10826@gmail.com>
  • Loading branch information
std-microblock and shigma authored Aug 14, 2024
1 parent 04b03c0 commit 399e84d
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion packages/sqlite/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Binary, deepEqual, Dict, difference, isNullable, makeArray, mapValues }
import { Driver, Eval, executeUpdate, Field, getCell, hasSubquery, isEvalExpr, Selection, z } from 'minato'
import { escapeId } from '@minatojs/sql-utils'
import { resolve } from 'node:path'
import { readFile, writeFile } from 'node:fs/promises'
import { access, readFile, writeFile } from 'node:fs/promises'
import { createRequire } from 'node:module'
import init from '@minatojs/sql.js'
import enUS from './locales/en-US.yml'
Expand Down Expand Up @@ -166,6 +166,15 @@ export class SQLiteDriver extends Driver<SQLiteDriver.Config> {
// @ts-ignore
: createRequire(import.meta.url || pathToFileURL(__filename).href).resolve('@minatojs/sql.js/dist/' + file),
})

if (this.path !== ':memory:') {
const dir = resolve(this.path, '..')
try {
await access(dir)
} catch {
throw new Error(`The database directory '${resolve(this.path, '..')}' is not accessible. You may have to create it first.`)
}
}
if (!isBrowser || this.path === ':memory:') {
this.db = new sqlite.Database(this.path)
} else {
Expand Down

0 comments on commit 399e84d

Please sign in to comment.