refactor(db): extract database configuration to separate file

Move database setup logic from index.ts to a dedicated database.ts file for better modularity. Update index.ts to re-export from the new file and adjust import in migrations.ts accordingly.
This commit is contained in:
2025-10-12 12:35:37 +00:00
parent b28b9fbfa2
commit b73745c56c
3 changed files with 15 additions and 14 deletions

View File

@@ -0,0 +1,13 @@
import { Database } from "bun:sqlite";
import { drizzle } from "drizzle-orm/bun-sqlite";
import * as schema from "./schema";
const sqlite = new Database(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,
});

View File

@@ -1,13 +1 @@
import { Database } from "bun:sqlite";
import { drizzle } from "drizzle-orm/bun-sqlite";
import * as schema from "./schema";
const sqlite = new Database(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,
});
export * from "./database";

View File

@@ -1,6 +1,6 @@
import path from "node:path";
import { migrate } from "drizzle-orm/bun-sqlite/migrator";
import { database } from ".";
import { database } from "./database";
async function runMigrations() {
// const client = new Database('database.db')