import type { DatabaseClient } from '../database/database-client.interface'; import type { QueryExecutor } from '../entity/db-context'; /** * Represents a deferred query that will be executed later. * Captures the SQL, parameters, and transformation logic at creation time. * * @typeParam TResult - The type of results this query will return */ export declare class FutureQuery { /** @internal */ readonly _sql: string; /** @internal */ readonly _params: any[]; /** @internal */ readonly _transformFn: (rows: any[]) => TResult[]; /** @internal */ readonly _client: DatabaseClient; /** @internal */ readonly _executor?: QueryExecutor; /** @internal */ readonly _mode: 'list' | 'single' | 'count'; constructor(sql: string, params: any[], transformFn: (rows: any[]) => TResult[], client: DatabaseClient, executor?: QueryExecutor, mode?: 'list' | 'single' | 'count'); /** * Get the SQL that will be executed */ getSql(): string; /** * Get the parameters for this query */ getParams(): any[]; /** * Execute this future query individually. * For batch execution, use FutureQueryRunner.runAsync() instead. */ execute(): Promise; /** * Transform raw database rows using this query's transformation function * @internal Used by FutureQueryRunner */ _transform(rows: any[]): TResult[]; } /** * A future query that returns a single result or null. * Not a subclass of FutureQuery to avoid type conflicts with execute() return type. */ export declare class FutureSingleQuery { /** @internal */ readonly _sql: string; /** @internal */ readonly _params: any[]; /** @internal */ readonly _transformFn: (rows: any[]) => TResult[]; /** @internal */ readonly _client: DatabaseClient; /** @internal */ readonly _executor?: QueryExecutor; /** @internal */ readonly _mode: 'single'; constructor(sql: string, params: any[], transformFn: (rows: any[]) => TResult[], client: DatabaseClient, executor?: QueryExecutor); /** * Get the SQL that will be executed */ getSql(): string; /** * Get the parameters for this query */ getParams(): any[]; /** * Execute this future query and return single result or null */ execute(): Promise; /** * Transform raw database rows using this query's transformation function * @internal Used by FutureQueryRunner */ _transform(rows: any[]): TResult[]; } /** * A future query that returns a count. * Not a subclass of FutureQuery to avoid type conflicts with execute() return type. */ export declare class FutureCountQuery { /** @internal */ readonly _sql: string; /** @internal */ readonly _params: any[]; /** @internal */ readonly _client: DatabaseClient; /** @internal */ readonly _executor?: QueryExecutor; /** @internal */ readonly _mode: 'count'; constructor(sql: string, params: any[], client: DatabaseClient, executor?: QueryExecutor); /** * Get the SQL that will be executed */ getSql(): string; /** * Get the parameters for this query */ getParams(): any[]; /** * Execute this future query and return the count */ execute(): Promise; /** * Transform raw database rows to count * @internal Used by FutureQueryRunner */ _transform(rows: any[]): number; } /** * Union type for all future query types */ export type AnyFutureQuery = FutureQuery | FutureSingleQuery | FutureCountQuery; /** * Type helper: Extract the result type from a FutureQuery */ export type FutureQueryResult = T extends FutureSingleQuery ? R | null : T extends FutureCountQuery ? number : T extends FutureQuery ? R[] : never; /** * Type helper for tuple of future queries results */ export type FutureQueryResults = { [K in keyof T]: FutureQueryResult; }; /** * Runner for executing multiple future queries in a single database roundtrip. * * @example * ```typescript * const q1 = db.users.select(u => ({ id: u.id, name: u.username })).future(); * const q2 = db.posts.select(p => ({ title: p.title })).futureFirstOrDefault(); * const q3 = db.comments.futureCount(); * * const [users, firstPost, commentCount] = await FutureQueryRunner.runAsync([q1, q2, q3]); * // users: { id: number, name: string }[] * // firstPost: { title: string } | null * // commentCount: number * ``` */ export declare class FutureQueryRunner { /** * Execute multiple future queries in a single database roundtrip when possible. * * If the database client supports multi-statement queries (PostgresClient), * all queries are combined and executed together. Otherwise, queries are * executed sequentially. * * @param futures - Array of future queries to execute * @returns Promise resolving to a tuple of results matching the input queries * * @example * ```typescript * const [users, posts, count] = await FutureQueryRunner.runAsync([ * db.users.select(u => ({ name: u.username })).future(), * db.posts.select(p => ({ title: p.title })).future(), * db.comments.futureCount() * ]); * ``` */ static runAsync(futures: T): Promise>; /** * Execute queries using multi-statement optimization (single roundtrip) */ private static executeMultiStatement; /** * Execute queries sequentially (fallback when multi-statement not available) */ private static executeSequential; } /** * Check if a value is a FutureQuery */ export declare function isFutureQuery(value: any): value is FutureQuery; /** * Check if a value is a FutureSingleQuery */ export declare function isFutureSingleQuery(value: any): value is FutureSingleQuery; /** * Check if a value is a FutureCountQuery */ export declare function isFutureCountQuery(value: any): value is FutureCountQuery; //# sourceMappingURL=future-query.d.ts.map