UNPKG

rawsql-ts

Version:

[beta]High-performance SQL parser and AST analyzer written in TypeScript. Provides fast parsing and advanced transformation capabilities.

53 lines (52 loc) 2 kB
import { SelectQuery, SimpleSelectQuery } from "../models/SelectQuery"; /** * Options for SqlParamInjector */ export interface SqlParamInjectorOptions { /** Whether to ignore case and underscore differences when matching column names */ ignoreCaseAndUnderscore?: boolean; /** Whether to allow injection when all parameters are undefined (defaults to false for safety) */ allowAllUndefined?: boolean; } /** * SqlParamInjector injects state parameters into a SelectQuery model, * creating WHERE conditions and setting parameter values. */ export declare class SqlParamInjector { private tableColumnResolver?; private options; constructor(optionsOrResolver?: SqlParamInjectorOptions | ((tableName: string) => string[]), options?: SqlParamInjectorOptions); /** * Injects parameters as WHERE conditions into the given query model. * @param query The SelectQuery to modify * @param state A record of parameter names and values * @returns The modified SelectQuery * @throws Error when all parameters are undefined and allowAllUndefined is not set to true */ inject(query: SimpleSelectQuery | string, state: Record<string, number | string | boolean | Date | null | undefined | Condition>): SelectQuery; } type BaseCondition = { '='?: number | string | boolean | Date; min?: number | string | Date; max?: number | string | Date; like?: string; ilike?: string; in?: (number | string | Date)[]; any?: (number | string | Date)[]; '<'?: number | string | Date; '>'?: number | string | Date; '!='?: number | string | boolean | Date; '<>'?: number | string | boolean | Date; '<='?: number | string | Date; '>='?: number | string | Date; }; type SingleCondition = BaseCondition & { column?: string; }; type LogicalCondition = { column?: string; and?: SingleCondition[]; or?: SingleCondition[]; }; type Condition = BaseCondition | SingleCondition | LogicalCondition; export {};