Files

16 lines
726 B
TypeScript

import { getDb } from "./index.ts";
/**
* One parameterised statement, its rows back.
*
* The narrowest way to reach the database, for the few modules whose whole
* job is a statement or two (the rate counter, the error sink, the owner's
* numbers). They take a `Run` instead of importing the pool, so their tests
* hand them an in-process Postgres built from the migration files and the
* statement that is tested is the statement that ships.
*/
export type Run = (text: string, params: readonly unknown[]) => Promise<readonly Record<string, unknown>[]>;
/** The app's pool. Built on first use, like `getDb`. */
export const run: Run = async (text, params) => (await getDb().$client.query(text, [...params])).rows;