import { getDatabase, withDatabaseRetry } from './client'; import type { SQLiteBindValue } from 'expo-sqlite'; export type DbSession = { runAsync(sql: string, ...params: SQLiteBindValue[]): Promise; getFirstAsync(sql: string, ...params: SQLiteBindValue[]): Promise; getAllAsync(sql: string, ...params: SQLiteBindValue[]): Promise; }; let override: DbSession | null = null; export function __setDbForTests(db: DbSession | null): void { override = db; } export async function getSession(): Promise { if (override) return override; await getDatabase(); return liveSession; } const liveSession: DbSession = { runAsync: (sql, ...params) => withDatabaseRetry((db) => db.runAsync(sql, ...params)), getFirstAsync: (sql, ...params) => withDatabaseRetry((db) => db.getFirstAsync(sql, ...params)), getAllAsync: (sql, ...params) => withDatabaseRetry((db) => db.getAllAsync(sql, ...params)), };