import * as z from 'zod'; import { QueryComposer } from '../core/query-composer'; /** * Recursive CTE Builder * * Builds WITH RECURSIVE queries for hierarchical data traversal. */ export declare class RecursiveCTEBuilder { private name; private schema; private baseQuery; private recursiveTable; private recursiveJoinCondition; private sourceTable; private includeDepth; private maxDepth; private additionalColumns; constructor(name: string, schema: T); /** * Define the base case (anchor member) * * @param queryFn - Function that configures the base query * @returns this for chaining * * @example * ```typescript * cte.baseCase(q => q.where({ parent_id__isnull: true })); * ``` */ baseCase(queryFn: (qc: QueryComposer) => QueryComposer): this; /** * Define the recursive case * * @param table - Source table to join with * @param joinCondition - Join condition between CTE and source table * @returns this for chaining * * @example * ```typescript * cte.recursiveCase('categories', 'tree.id = categories.parent_id'); * ``` */ recursiveCase(table: string, joinCondition: string): this; /** * Set the source table * * @param table - Table name * @returns this for chaining */ from(table: string): this; /** * Add depth tracking column * * @returns this for chaining */ withDepth(): this; /** * Set maximum recursion depth * * @param depth - Maximum depth * @returns this for chaining */ withMaxDepth(depth: number): this; /** * Add additional columns to track through recursion * * @param columns - Column names * @returns this for chaining */ withColumns(...columns: string[]): this; /** * Generate parameterized query. * Uses $N placeholders for base query values to prevent SQL injection. * * @returns Object with text and values */ toParam(): { text: string; values: unknown[]; }; /** * Generate SQL string with inlined values (for debugging only). * WARNING: Do NOT use for query execution — use toParam() instead. * * @returns SQL string with inlined values */ toSQL(): string; /** * Get column list */ private getColumnList; } /** * Create a recursive CTE builder * * @param name - CTE name * @param schema - Zod schema for the table * @returns RecursiveCTEBuilder instance * * @example * ```typescript * // Find all descendants of a category * const descendants = createRecursiveCTE('descendants', CategorySchema) * .from('categories') * .baseCase(q => q.where({ id: rootId })) * .recursiveCase('categories', 'descendants.id = categories.parent_id') * .withDepth(); * * const { text, values } = descendants.toParam(); * // Execute: db.query(text, values) * ``` */ export declare function createRecursiveCTE(name: string, schema: T): RecursiveCTEBuilder; /** * Create ancestors traversal CTE * * Helper for common ancestor traversal pattern. * * @param table - Table name * @param schema - Zod schema * @param startId - Starting node ID * @param parentColumn - Column pointing to parent (default: 'parent_id') * @returns RecursiveCTEBuilder configured for ancestor traversal */ export declare function ancestorsCTE(table: string, schema: T, startId: string, parentColumn?: string): RecursiveCTEBuilder; /** * Create descendants traversal CTE * * Helper for common descendant traversal pattern. * * @param table - Table name * @param schema - Zod schema * @param rootId - Root node ID * @param parentColumn - Column pointing to parent (default: 'parent_id') * @returns RecursiveCTEBuilder configured for descendant traversal */ export declare function descendantsCTE(table: string, schema: T, rootId: string, parentColumn?: string): RecursiveCTEBuilder; //# sourceMappingURL=recursive.d.ts.map