/** * sql.helpers.ts * * Helpers that wrap common use cases for the `sql` template literal from [sql.ts](./sql.ts) */ import { ArrayElement, Query, SqlDatabase, SqlInterface } from './sql.types'; /** * Return the first element, after the query is run, returns undefined if result is empty * * ```typescript * const showSql = sql` * SELECT id, name * FROM table1 * WHERE id = $id * `; * const showQuery = maybeOneResult(showSql); * * const myRowItem = await showQuery(db, { id: 12 }); * ``` */ export declare const maybeOneResult: >(query: Query) => Query | undefined>, TQueryInterface["result"]>; /** * Return the first element, useful for queries where we always expect at least one result * * @throws PotygenRuntimeError if row is empty * * ```typescript * const showSql = sql` * INSERT (name) * INTO table1 * VALUES ($name) * RETURNING id, name * `; * const showQuery = oneResult(showSql); * * const myRowItem = await showQuery(db, { name: 'myNewRow' }); * * ``` */ export declare const oneResult: >(query: Query) => Query>, TQueryInterface["result"]>; /** * Return the rows but throw an error if no rows have been returned * * @throws PotygenRuntimeError if row is empty * * ```typescript * const showSql = sql` * INSERT (name) * INTO table1 * VALUES ($name) * RETURNING id, name * `; * const showQuery = atLeastOneResult(showSql); * * const myRowItem = await showQuery(db, { name: 'myNewRow' }); * * ``` */ export declare const atLeastOneResult: >(query: Query) => Query, TQueryInterface["result"]>; /** * Return the first element, useful for queries where we always expect at least one result * * @throws PotygenRuntimeError if row is empty * * ```typescript * const showSql = sql` * SELECT id, name * FROM table1 * WHERE id = $id * `; * const idsQuery = map((rows) => rows.map(({ id }) => id)), showSql); * * const ids = await showQuery(db, { name: 'myNewRow' }); * * ``` */ export declare const mapResult: = SqlInterface, TOriginalResult = TSqlInterface["result"]>(mapper: (rows: TSqlInterface["result"], db: SqlDatabase, params: TSqlInterface["params"]) => TMappedResult, query: Query) => Query, TSqlInterface["result"]>;