import * as z from 'zod'; import { SelectBuilder } from './sql-builder'; import type { QueryBuilderOptions, PaginationOptions, PaginationMeta, Condition, OrGroup } from './types'; /** * Columns accepted in filters even when the schema omits them. * * These are a naming convention, not a fact about the table — a schema using * `inserted_at`, `createdAt` or no soft-delete column at all should override * them via `QueryBuilderOptions.defaultColumns` (pass `[]` to accept only what * the schema declares). Filter-only either way: their presence is an * assumption, so they are never expanded into a projection. */ export declare const DEFAULT_FILTER_COLUMNS: readonly string[]; /** * Advanced SQL Query Composer * * A fluent, chainable query builder that supports: * - Django-style field__operator syntax * - AND/OR clause composition * - Pagination with metadata * - Flexible sorting * - Column validation via Zod schema * - SQL injection prevention */ export declare class QueryComposer { private schema; private table; private fromTable; private options; private whitelist; private whitelistSet; private projectableColumns; private aliasByColumn; private conditions; private orGroups; private notConditions; private sortOptions; private paginationOptions; private selectedFields; private excludedFields; private joins; private groupByFields; private havingConditions; /** * Create a new QueryComposer instance */ constructor(schema: z.ZodTypeAny, table: string, options?: QueryBuilderOptions); private validateColumn; private validateOperator; private parseFieldOperator; /** * Add WHERE conditions (AND logic) * * Accepts a plain filter object (`{ age__gte: 18 }`) and/or a branded raw * filter produced by the JSONB/FTS/EXISTS helpers. A `__raw` key that is NOT * branded — i.e. anything reaching here from untrusted input such as * `req.query` — is treated as an ordinary column name and rejected by the * whitelist, so raw SQL cannot be smuggled through user-supplied filters. */ where(filters: Record): this; /** * Add raw WHERE condition */ whereRaw(condition: string, values?: unknown[]): this; /** * Add OR conditions group */ or(filterGroups: Array>): this; /** * Add NOT conditions */ not(filters: Record): this; /** * Add WHERE IN with subquery or array values. * Subqueries preserve parameterization (no inline value interpolation). */ whereIn(column: string, subqueryOrValues: QueryComposer | readonly unknown[]): this; /** * Add WHERE NOT IN with subquery or array values. * Subqueries preserve parameterization (no inline value interpolation). */ whereNotIn(column: string, subqueryOrValues: QueryComposer | readonly unknown[]): this; /** * Select specific fields */ select(fields: string[]): this; /** * Exclude specific fields from selection */ exclude(fields: string[]): this; /** * Add ORDER BY clause */ orderBy(...fields: string[]): this; /** * Clear all sorting */ clearSort(): this; /** * Add pagination */ paginate(options: PaginationOptions): this; /** * Get pagination metadata */ getPaginationMeta(total?: number): PaginationMeta; /** * Add INNER JOIN */ join(table: string, on: string, alias?: string): this; /** * Add LEFT JOIN */ leftJoin(table: string, on: string, alias?: string): this; /** * Add RIGHT JOIN */ rightJoin(table: string, on: string, alias?: string): this; /** * Add GROUP BY clause */ groupBy(...fields: string[]): this; /** * Add HAVING clause */ having(condition: string, values?: unknown[]): this; /** * Conditionally apply query modifications * @param condition - Boolean or function returning boolean * @param callback - Function to apply if condition is truthy */ when(condition: boolean | (() => boolean) | unknown, callback: (qc: QueryComposer) => QueryComposer): this; /** * Apply query modifications unless condition is true * @param condition - Boolean or function returning boolean * @param callback - Function to apply if condition is falsy */ unless(condition: boolean | (() => boolean) | unknown, callback: (qc: QueryComposer) => QueryComposer): this; /** * Apply a scope to the query */ apply(scopeDef: { apply: (qc: QueryComposer) => QueryComposer; }): this; private applyConditions; private applyJoins; /** * Build SELECT query */ toSelect(): SelectBuilder; /** * Build COUNT query */ toCount(): SelectBuilder; /** * Get parameterized query for SELECT */ toParam(): { text: string; values: unknown[]; }; /** * Get parameterized query for COUNT */ toCountParam(): { text: string; values: unknown[]; }; /** * Get SQL string (for debugging) */ toSQL(): string; /** * Clone this composer */ clone(): QueryComposer; /** * Reset all conditions */ reset(): this; /** * Get internal state for merging */ getInternalState(): { conditions: Condition[]; orGroups: OrGroup[]; notConditions: Condition[]; }; /** * Merge conditions from another QueryComposer */ mergeFrom(other: QueryComposer): this; } /** * Create a QueryComposer instance */ export declare function createQueryComposer(schema: z.ZodTypeAny, table: string, options?: QueryBuilderOptions): QueryComposer; //# sourceMappingURL=query-composer.d.ts.map