import { Database } from "bun:sqlite";
import path from "node:path";
import { drizzle } from "drizzle-orm/bun-sqlite";
import { getDataDirectory } from "@/utils/directories";
import * as schema from "./schema";

const sqlite = new Database(
	path.join(getDataDirectory(), process.env.DATABASE_FILENAME ?? "database.db"),
);

// Enable WAL mode for improved performance with concurrent readers
sqlite.run("PRAGMA journal_mode = WAL;");

export const database = drizzle({
	client: sqlite,
	schema: schema,
});
