From 307027846c7b798d0b95d9fdb0dec7f1fac7e140 Mon Sep 17 00:00:00 2001 From: moriese Date: Sat, 25 Jan 2025 02:05:42 +0100 Subject: [PATCH] fixed mybe? --- src/db/index.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/db/index.ts b/src/db/index.ts index e08e96c..a504a3a 100644 --- a/src/db/index.ts +++ b/src/db/index.ts @@ -1,4 +1,18 @@ +import fs from 'node:fs'; +import path from 'node:path'; import { drizzle } from "drizzle-orm/bun-sqlite"; +import { Database } from 'bun:sqlite'; // biome-ignore lint/style/noNonNullAssertion: -export const db = drizzle(process.env.DB_FILE_NAME!); \ No newline at end of file +const dbPath = process.env.DB_FILE_NAME!; +const dbDir = path.dirname(dbPath); + +// Create directory if it doesn't exist +if (!fs.existsSync(dbDir)) { + fs.mkdirSync(dbDir, { recursive: true }); +} + +// Ensure database file can be created +const client = new Database(dbPath); + +export const db = drizzle(client); \ No newline at end of file