2026-05-18 20:50:48 +00:00
|
|
|
/**
|
2026-05-26 11:22:29 +00:00
|
|
|
* Backend-agnostic DB adapter. Repository talks to this; PG adapter implements it.
|
2026-05-18 20:50:48 +00:00
|
|
|
*
|
|
|
|
|
* Design choices:
|
2026-05-26 11:22:29 +00:00
|
|
|
* - All methods return Promises (real async I/O with PG pool).
|
|
|
|
|
* - `?` is the canonical placeholder in SQL strings. The PG adapter
|
2026-05-18 20:50:48 +00:00
|
|
|
* rewrites them to `$1, $2, ...` at execute time so repository code stays
|
|
|
|
|
* dialect-neutral.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
export type SqlValue = string | number | bigint | boolean | null | Uint8Array;
|
|
|
|
|
export type Row = Record<string, unknown>;
|
|
|
|
|
|
|
|
|
|
export interface RunResult {
|
|
|
|
|
lastInsertRowid: bigint;
|
|
|
|
|
changes: number;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface DbAdapter {
|
|
|
|
|
run(sql: string, params?: ReadonlyArray<SqlValue>): Promise<RunResult>;
|
|
|
|
|
get<T = Row>(sql: string, params?: ReadonlyArray<SqlValue>): Promise<T | undefined>;
|
|
|
|
|
all<T = Row>(sql: string, params?: ReadonlyArray<SqlValue>): Promise<T[]>;
|
|
|
|
|
exec(sql: string): Promise<void>;
|
|
|
|
|
transaction<T>(fn: () => Promise<T>): Promise<T>;
|
2026-05-26 11:22:29 +00:00
|
|
|
dialect(): "postgres";
|
2026-05-26 05:22:01 +00:00
|
|
|
setSearchPath(schema: string): Promise<void>;
|
2026-05-18 20:50:48 +00:00
|
|
|
close(): Promise<void>;
|
|
|
|
|
}
|