import type { Schema } from '../../../zero-schema/src/builder/schema-builder.ts';
import type { DBConnection, DBTransaction, Row } from '../../../zql/src/mutate/custom.ts';
import postgres from 'postgres';
import { ZQLDatabase } from '../zql-database.ts';
/**
 * Helper type for the wrapped transaction used by postgres.js.
 *
 * @typeParam T - The row-shape context bound to the postgres.js client.
 * @remarks Use with `ServerTransaction` as `ServerTransaction<Schema, PostgresJsTransaction>`.
 */
export type PostgresJsTransaction<T extends Record<string, unknown> = Record<string, unknown>> = postgres.TransactionSql<T>;
export declare class PostgresJSConnection<T extends Record<string, unknown>> implements DBConnection<PostgresJsTransaction<T>> {
    #private;
    constructor(pg: postgres.Sql<T>);
    transaction<TRet>(fn: (tx: DBTransaction<PostgresJsTransaction<T>>) => Promise<TRet>): Promise<TRet>;
}
export declare class PostgresJsTransactionInternal<T extends Record<string, unknown>> implements DBTransaction<PostgresJsTransaction<T>> {
    readonly wrappedTransaction: PostgresJsTransaction<T>;
    constructor(pgTx: PostgresJsTransaction<T>);
    query(sql: string, params: unknown[]): Promise<Row[]>;
}
/**
 * Wrap a `postgres` client for Zero ZQL.
 *
 * Provides ZQL querying plus access to the underlying postgres.js transaction.
 * Use {@link PostgresJsTransaction} to type your server mutator transaction.
 *
 * @param schema - Zero schema.
 * @param pg - `postgres` client or connection string.
 *
 * @example
 * ```ts
 * import postgres from 'postgres';
 *
 * const sql = postgres(process.env.ZERO_UPSTREAM_DB!);
 * const zql = zeroPostgresJS(schema, sql);
 *
 * // Define the server mutator transaction type using the helper
 * type ServerTx = ServerTransaction<
 *   Schema,
 *   PostgresJsTransaction
 * >;
 *
 * async function createUser(
 *   tx: ServerTx,
 *   {id, name}: {id: string; name: string},
 * ) {
 *   await tx.dbTransaction.wrappedTransaction
 *     .unsafe('INSERT INTO "user" (id, name) VALUES ($1, $2)', [id, name]);
 * }
 * ```
 */
export declare function zeroPostgresJS<S extends Schema, T extends Record<string, unknown> = Record<string, unknown>>(schema: S, pg: postgres.Sql<T> | string): ZQLDatabase<S, PostgresJsTransaction<T>>;
//# sourceMappingURL=postgresjs.d.ts.map