export type SqlValue = string | number | bigint | null | Uint8Array; export type Row = Record; /** * The subset of the Turso database API used by the repositories. Both * `@tursodatabase/database-wasm` (browser) and `@tursodatabase/database` (Node, used in tests) * satisfy this interface. */ export interface DbConnection { exec(sql: string): Promise; run(sql: string, ...params: SqlValue[]): Promise<{ changes: number; lastInsertRowid: number }>; get(sql: string, ...params: SqlValue[]): Promise; all(sql: string, ...params: SqlValue[]): Promise; close(): Promise; } /** Runs `fn` inside a transaction, rolling back on failure. */ export async function withTransaction(db: DbConnection, fn: () => Promise): Promise { await db.exec("BEGIN"); try { const result = await fn(); await db.exec("COMMIT"); return result; } catch (error) { await db.exec("ROLLBACK"); throw error; } }