import { type SQL } from 'drizzle-orm';
import type { PgDatabase, PgQueryResultHKT, PgTransaction } from 'drizzle-orm/pg-core';
import type { ExtractTablesWithRelations } from 'drizzle-orm/relations';
import type { Schema } from '../../../zero-schema/src/builder/schema-builder.ts';
import type { DBConnection, DBTransaction, Row } from '../../../zql/src/mutate/custom.ts';
import { ZQLDatabase } from '../zql-database.ts';
export type DrizzleDatabase<TQueryResult extends PgQueryResultHKT = PgQueryResultHKT, TSchema extends Record<string, unknown> = Record<string, unknown>, TClient = unknown> = PgDatabase<TQueryResult, TSchema> & {
    $client: TClient;
};
/**
 * Helper type for the wrapped transaction used by drizzle-orm.
 *
 * @remarks Use with `ServerTransaction` as `ServerTransaction<Schema, DrizzleTransaction<typeof drizzleDb>>`.
 */
export type DrizzleTransaction<TDbOrSchema extends DrizzleDatabase | Record<string, unknown>, TSchema extends Record<string, unknown> = TDbOrSchema extends PgDatabase<PgQueryResultHKT, infer TInferredSchema> ? TInferredSchema : TDbOrSchema> = PgTransaction<PgQueryResultHKT, TSchema, ExtractTablesWithRelations<TSchema>>;
export declare class DrizzleConnection<TDrizzle extends DrizzleDatabase, TTransaction extends DrizzleTransaction<TDrizzle> = DrizzleTransaction<TDrizzle>> implements DBConnection<TTransaction> {
    #private;
    constructor(drizzle: TDrizzle);
    transaction<T>(fn: (tx: DBTransaction<TTransaction>) => Promise<T>): Promise<T>;
}
/**
 * Turn `$1, $2...` placeholders into a Drizzle SQL object with bound params.
 */
export declare function fromDollarParams(text: string, params: unknown[]): SQL;
export declare function toIterableRows(result: unknown): Iterable<Row>;
/**
 * Wrap a `drizzle-orm` database for Zero ZQL.
 *
 * Provides ZQL querying plus access to the underlying drizzle transaction.
 * Use {@link DrizzleTransaction} to type your server mutator transaction.
 *
 * @param schema - Zero schema.
 * @param client - Drizzle database.
 *
 * @example
 * ```ts
 * import {Pool} from 'pg';
 * import {drizzle} from 'drizzle-orm/node-postgres';
 * import type {ServerTransaction} from '@rocicorp/zero';
 *
 * const pool = new Pool({connectionString: process.env.ZERO_UPSTREAM_DB!});
 * const drizzleDb = drizzle(pool, {schema: drizzleSchema});
 *
 * const zql = zeroDrizzle(schema, drizzleDb);
 *
 * // Define the server mutator transaction type using the helper
 * type ServerTx = ServerTransaction<Schema, DrizzleTransaction<typeof drizzleDb>>;
 *
 * async function createUser(
 *   tx: ServerTx,
 *   {id, name}: {id: string; name: string},
 * ) {
 *   await tx.dbTransaction.wrappedTransaction
 *     .insert(drizzleSchema.user)
 *     .values({id, name})
 * }
 * ```
 */
export declare function zeroDrizzle<S extends Schema, TDrizzle extends DrizzleDatabase>(schema: S, client: TDrizzle): ZQLDatabase<S, DrizzleTransaction<TDrizzle>>;
//# sourceMappingURL=drizzle.d.ts.map