attempt to replace better-sqlite with libsql
This commit is contained in:
@@ -1,23 +1,26 @@
|
||||
import type { BetterSQLite3Database } from "drizzle-orm/better-sqlite3";
|
||||
import type { LibSQLDatabase } from "drizzle-orm/libsql";
|
||||
export async function initDb() {
|
||||
await import("dotenv/config");
|
||||
// await import("dotenv/config");
|
||||
// import type { BunSQLiteDatabase } from "drizzle-orm/bun-sqlite";
|
||||
|
||||
let _db: BetterSQLite3Database;
|
||||
let _db: LibSQLDatabase;
|
||||
|
||||
if (!process.env.DB_FILE_NAME) {
|
||||
console.error("[DEBUG] Environment check failed. DB_FILE_NAME is missing.");
|
||||
console.error("[DEBUG] PWD:", process.cwd());
|
||||
// Only log keys to avoid leaking secrets, filtering for DB_
|
||||
console.error(
|
||||
"[DEBUG] Keys in env:",
|
||||
Object.keys(process.env).filter((k) => k.includes("DB")),
|
||||
);
|
||||
throw new Error("DB_FILE_NAME is not set");
|
||||
}
|
||||
|
||||
console.info("Using DB_FILE_NAME: ", process.env.DB_FILE_NAME);
|
||||
|
||||
// if (process.versions.bun) {
|
||||
// console.info("Using Bun SQLite");
|
||||
// const { drizzle } = await import("drizzle-orm/bun-sqlite");
|
||||
// _db = drizzle(process.env.DB_FILE_NAME);
|
||||
// } else {
|
||||
console.info("Using Better SQLite3");
|
||||
const { drizzle } = await import("drizzle-orm/better-sqlite3");
|
||||
console.info("Using LibSQL");
|
||||
const { drizzle } = await import("drizzle-orm/libsql");
|
||||
_db = drizzle(process.env.DB_FILE_NAME);
|
||||
// }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user