/** * Generic in-memory store (fallback when no PostgreSQL) */ type Store = Map; const stores = new Map(); function getStore(table: string): Store { if (!stores.has(table)) stores.set(table, new Map()); return stores.get(table)!; } export const memoryDB = { create(table: string, id: string, data: any): any { const store = getStore(table); const record = { ...data, id }; store.set(id, record); return record; }, getById(table: string, id: string): any | undefined { return getStore(table).get(id); }, list(table: string, filter?: (item: any) => boolean): any[] { const items = Array.from(getStore(table).values()); return filter ? items.filter(filter) : items; }, update(table: string, id: string, data: Partial): any | null { const store = getStore(table); const existing = store.get(id); if (!existing) return null; const updated = { ...existing, ...data }; store.set(id, updated); return updated; }, delete(table: string, id: string): boolean { return getStore(table).delete(id); }, count(table: string, filter?: (item: any) => boolean): number { return this.list(table, filter).length; }, };