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:
13
apps/server/src/db/database.ts
Normal file
13
apps/server/src/db/database.ts
Normal 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,
|
||||
});
|
||||
@@ -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";
|
||||
|
||||
@@ -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')
|
||||
|
||||
Reference in New Issue
Block a user