tomfoolery works when serving with node but not with cloudflare, look into hosting the db with turso

This commit is contained in:
2026-02-09 17:22:43 -08:00
parent 6d0e76288c
commit 4be1c19481
3 changed files with 10 additions and 4 deletions

View File

@@ -6,7 +6,6 @@
"name": "amqtrain",
"dependencies": {
"@libsql/client": "^0.17.0",
"dotenv": "^17.2.4",
},
"devDependencies": {
"@biomejs/biome": "^2.3.14",
@@ -21,6 +20,7 @@
"@types/node": "^25.2.0",
"bits-ui": "^2.14.4",
"clsx": "^2.1.1",
"dotenv": "^17.2.4",
"drizzle-kit": "^0.31.8",
"drizzle-orm": "^0.45.1",
"lefthook": "^2.1.0",

View File

@@ -31,6 +31,7 @@
"@types/node": "^25.2.0",
"bits-ui": "^2.14.4",
"clsx": "^2.1.1",
"dotenv": "^17.2.4",
"drizzle-kit": "^0.31.8",
"drizzle-orm": "^0.45.1",
"lefthook": "^2.1.0",
@@ -51,7 +52,6 @@
"runed@0.37.1": "patches/runed@0.37.1.patch"
},
"dependencies": {
"@libsql/client": "^0.17.0",
"dotenv": "^17.2.4"
"@libsql/client": "^0.17.0"
}
}

View File

@@ -1,10 +1,13 @@
import type { LibSQLDatabase } from "drizzle-orm/libsql";
import { browser, dev } from "$app/environment";
export async function initDb() {
// await import("dotenv/config");
// import type { BunSQLiteDatabase } from "drizzle-orm/bun-sqlite";
let _db: LibSQLDatabase;
if (dev) process.env.DB_FILE_NAME = "file:static/data/amq.sqlite";
if (!process.env.DB_FILE_NAME) {
console.error("[DEBUG] Environment check failed. DB_FILE_NAME is missing.");
console.error("[DEBUG] PWD:", process.cwd());
@@ -20,8 +23,11 @@ export async function initDb() {
// _db = drizzle(process.env.DB_FILE_NAME);
// } else {
console.info("Using LibSQL");
const { createClient } = browser
? await import("@libsql/client")
: await import("@libsql/client/node");
const { drizzle } = await import("drizzle-orm/libsql");
_db = drizzle(process.env.DB_FILE_NAME);
_db = drizzle(createClient({ url: process.env.DB_FILE_NAME! }));
// }
return _db;