import type { ComparisonFilterOperator, DistinctFilterOperator, LikeFilterOperator, ListFilterOperator, PatternFilterOperator } from 'query-spec'; export type SqlValue = string | number | boolean | null; export interface QueryOutput { text: string; values: SqlValue[]; } export type Operand = SqlValue | Expr; export type FieldFilter = { isNull?: boolean; } & { [K in ComparisonFilterOperator]?: Operand | QueryBuilder; } & { [K in DistinctFilterOperator]?: Operand; } & { [K in ListFilterOperator]?: Operand[] | QueryBuilder; } & { [K in LikeFilterOperator]?: Operand; } & { [K in PatternFilterOperator]?: string; }; export type Filter = { [field: string]: FieldFilter | Filter[] | Filter | undefined; } & { and?: Filter[]; or?: Filter[]; not?: Filter; }; type SortDir = 'ASC' | 'DESC'; type NullsOrder = 'FIRST' | 'LAST'; type ConflictAction = 'nothing' | 'update'; export type LockStrength = 'update' | 'noKeyUpdate' | 'share' | 'keyShare'; export interface LockOptions { skipLocked?: boolean; noWait?: boolean; } export interface SelectExpr { expr: Expr; as?: string; } export type SelectItem = string | SelectExpr; type JoinOpts = { schema?: string; alias?: string; }; interface OnConflictSpec { columns?: string[]; constraint?: string; action: ConflictAction; updateColumns?: Record; where?: Filter; } export type ParamAllocator = (value: SqlValue) => unknown; export type Expr = (alloc: ParamAllocator) => unknown; export type FnArg = Expr | SqlValue; export type FnArgs = FnArg[] | Record; export declare function col(name: string): Expr; export declare function lit(value: SqlValue): Expr; export declare function param(value: SqlValue): Expr; export declare function fn(name: string, args?: FnArgs, opts?: { schema?: string; }): Expr; export declare const eq: (left: Operand, right: Operand) => Expr; export declare const neq: (left: Operand, right: Operand) => Expr; export declare const lt: (left: Operand, right: Operand) => Expr; export declare const lte: (left: Operand, right: Operand) => Expr; export declare const gt: (left: Operand, right: Operand) => Expr; export declare const gte: (left: Operand, right: Operand) => Expr; export declare const add: (left: Operand, right: Operand) => Expr; export declare const sub: (left: Operand, right: Operand) => Expr; export declare const mul: (left: Operand, right: Operand) => Expr; export declare const div: (left: Operand, right: Operand) => Expr; export declare function cast(x: Operand, typeName: string): Expr; export declare function isNull(x: Operand): Expr; export declare function isNotNull(x: Operand): Expr; export declare function and(...xs: Expr[]): Expr; export declare function or(...xs: Expr[]): Expr; export declare function not(x: Expr): Expr; export declare class QueryBuilder { private _schema; private _table; private _tableAlias; private _selectItems; private _distinct; private _insertData; private _updateData; private _isDelete; private _wherePredicates; private _joins; private _groupByColumns; private _havingPredicates; private _orderBySpecs; private _fromFunction; private _limitValue; private _offsetValue; private _returning; private _ctes; private _onConflict; private _funcCall; private _lock; schema(name: string): this; table(name: string, alias?: string): this; select(columns?: SelectItem[]): this; selectCall(as: string, name: string, args?: FnArgs, opts?: { schema?: string; }): this; selectExpr(as: string, expr: Expr): this; distinct(): this; insert(data: Record | Record[]): this; onConflict(spec: OnConflictSpec): this; update(data: Record): this; delete(): this; where(...predicates: (Filter | Expr)[]): this; join(kind: 'INNER' | 'LEFT' | 'RIGHT' | 'FULL', table: string, on: Filter | Expr, opts?: JoinOpts): this; join(kind: 'INNER' | 'LEFT' | 'RIGHT' | 'FULL', table: string, onColumn: string, operator: string, onValue: string, opts?: JoinOpts): this; innerJoin(table: string, on: Filter | Expr, opts?: JoinOpts): this; innerJoin(table: string, onCol: string, op: string, onVal: string, opts?: JoinOpts): this; leftJoin(table: string, on: Filter | Expr, opts?: JoinOpts): this; leftJoin(table: string, onCol: string, op: string, onVal: string, opts?: JoinOpts): this; rightJoin(table: string, on: Filter | Expr, opts?: JoinOpts): this; rightJoin(table: string, onCol: string, op: string, onVal: string, opts?: JoinOpts): this; fullJoin(table: string, on: Filter | Expr, opts?: JoinOpts): this; fullJoin(table: string, onCol: string, op: string, onVal: string, opts?: JoinOpts): this; groupBy(columns: (string | Expr)[]): this; having(...predicates: (Filter | Expr)[]): this; orderBy(column: string | Expr, direction?: SortDir, nulls?: NullsOrder): this; limit(n: number): this; offset(n: number): this; lock(strength?: LockStrength, opts?: LockOptions): this; returning(columns?: SelectItem[]): this; with(name: string, query: QueryBuilder, opts?: { columns?: string[]; materialized?: 'default' | 'always' | 'never'; }): this; withRecursive(name: string, query: QueryBuilder, opts?: { columns?: string[]; materialized?: 'default' | 'always' | 'never'; }): this; call(name: string, args?: FnArgs, opts?: { schema?: string; as?: string; }): this; fromFunction(name: string, args?: FnArgs, opts?: { schema?: string; as?: string; }): this; clone(): QueryBuilder; build(): QueryOutput; toSQL(): string; private _paramValues; private _paramIndex; private _resetParams; private _addParam; private get _alloc(); private _buildTargetList; private _buildPredicates; private _filterToNode; private static readonly _comparisonOps; private static readonly _likeOps; private static readonly _patternOps; private _subqueryNode; private _fieldOpToNode; private _buildReturningClause; private _buildWithClause; private _joinQuals; private _buildFromClause; private _rangeFunctionNode; private _buildSelectInternal; private _buildLockingClause; private _buildSelect; private _buildInsert; private _buildOnConflictClause; private _buildUpdate; private _buildDelete; private _buildFuncCall; } export {};