import { Database } from 'bun:sqlite'; import { applySchema } from './schema'; let db: Database | null = null; export function getDb(): Database { if (db) return db; const path = process.env.DB_PATH || './data/shop.db'; db = new Database(path, { create: true }); applySchema(db); return db; } export function closeDb() { if (db) { try { db.close(); } catch {} db = null; } }