1 import { Database } from 'bun:sqlite'; 2 import { applySchema } from './schema'; 3 4 let db: Database | null = null; 5 6 export function getDb(): Database { 7 if (db) return db; 8 const path = process.env.DB_PATH || './data/shop.db'; 9 db = new Database(path, { create: true }); 10 applySchema(db); 11 return db; 12 } 13 14 export function closeDb() { 15 if (db) { 16 try { db.close(); } catch {} 17 db = null; 18 } 19 } 20