tomfoolery works when serving with node but not with cloudflare, look into hosting the db with turso
This commit is contained in:
2
bun.lock
2
bun.lock
@@ -6,7 +6,6 @@
|
|||||||
"name": "amqtrain",
|
"name": "amqtrain",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@libsql/client": "^0.17.0",
|
"@libsql/client": "^0.17.0",
|
||||||
"dotenv": "^17.2.4",
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@biomejs/biome": "^2.3.14",
|
"@biomejs/biome": "^2.3.14",
|
||||||
@@ -21,6 +20,7 @@
|
|||||||
"@types/node": "^25.2.0",
|
"@types/node": "^25.2.0",
|
||||||
"bits-ui": "^2.14.4",
|
"bits-ui": "^2.14.4",
|
||||||
"clsx": "^2.1.1",
|
"clsx": "^2.1.1",
|
||||||
|
"dotenv": "^17.2.4",
|
||||||
"drizzle-kit": "^0.31.8",
|
"drizzle-kit": "^0.31.8",
|
||||||
"drizzle-orm": "^0.45.1",
|
"drizzle-orm": "^0.45.1",
|
||||||
"lefthook": "^2.1.0",
|
"lefthook": "^2.1.0",
|
||||||
|
|||||||
@@ -31,6 +31,7 @@
|
|||||||
"@types/node": "^25.2.0",
|
"@types/node": "^25.2.0",
|
||||||
"bits-ui": "^2.14.4",
|
"bits-ui": "^2.14.4",
|
||||||
"clsx": "^2.1.1",
|
"clsx": "^2.1.1",
|
||||||
|
"dotenv": "^17.2.4",
|
||||||
"drizzle-kit": "^0.31.8",
|
"drizzle-kit": "^0.31.8",
|
||||||
"drizzle-orm": "^0.45.1",
|
"drizzle-orm": "^0.45.1",
|
||||||
"lefthook": "^2.1.0",
|
"lefthook": "^2.1.0",
|
||||||
@@ -51,7 +52,6 @@
|
|||||||
"runed@0.37.1": "patches/runed@0.37.1.patch"
|
"runed@0.37.1": "patches/runed@0.37.1.patch"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@libsql/client": "^0.17.0",
|
"@libsql/client": "^0.17.0"
|
||||||
"dotenv": "^17.2.4"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,13 @@
|
|||||||
import type { LibSQLDatabase } from "drizzle-orm/libsql";
|
import type { LibSQLDatabase } from "drizzle-orm/libsql";
|
||||||
|
import { browser, dev } from "$app/environment";
|
||||||
export async function initDb() {
|
export async function initDb() {
|
||||||
// await import("dotenv/config");
|
// await import("dotenv/config");
|
||||||
// import type { BunSQLiteDatabase } from "drizzle-orm/bun-sqlite";
|
// import type { BunSQLiteDatabase } from "drizzle-orm/bun-sqlite";
|
||||||
|
|
||||||
let _db: LibSQLDatabase;
|
let _db: LibSQLDatabase;
|
||||||
|
|
||||||
|
if (dev) process.env.DB_FILE_NAME = "file:static/data/amq.sqlite";
|
||||||
|
|
||||||
if (!process.env.DB_FILE_NAME) {
|
if (!process.env.DB_FILE_NAME) {
|
||||||
console.error("[DEBUG] Environment check failed. DB_FILE_NAME is missing.");
|
console.error("[DEBUG] Environment check failed. DB_FILE_NAME is missing.");
|
||||||
console.error("[DEBUG] PWD:", process.cwd());
|
console.error("[DEBUG] PWD:", process.cwd());
|
||||||
@@ -20,8 +23,11 @@ export async function initDb() {
|
|||||||
// _db = drizzle(process.env.DB_FILE_NAME);
|
// _db = drizzle(process.env.DB_FILE_NAME);
|
||||||
// } else {
|
// } else {
|
||||||
console.info("Using LibSQL");
|
console.info("Using LibSQL");
|
||||||
|
const { createClient } = browser
|
||||||
|
? await import("@libsql/client")
|
||||||
|
: await import("@libsql/client/node");
|
||||||
const { drizzle } = await import("drizzle-orm/libsql");
|
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;
|
return _db;
|
||||||
|
|||||||
Reference in New Issue
Block a user