import { env } from '$env/dynamic/private'; import { join } from 'node:path'; import { createDatabase, type Db } from './db'; import { SqliteCache, type Cache } from './cache'; let db: Db | undefined; let cache: Cache | undefined; /** Process-wide SQLite handle, opened lazily at the configured data directory. */ export function getDb(): Db { if (!db) { const dir = env.TWINKL_DATA_DIR ?? './data'; db = createDatabase(join(dir, 'twinkl.sqlite')); } return db; } export function getCache(): Cache { if (!cache) { cache = new SqliteCache(getDb()); } return cache; }