UNPKG

rawsql-ts

Version:

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

81 lines (80 loc) 3.23 kB
import { SelectQuery } from '../models/SelectQuery'; import { TableColumnResolver } from './TableColumnResolver'; /** * Options for FilterableItemCollector */ export interface FilterableItemCollectorOptions { /** If true, return qualified names (table.column), if false return column names only */ qualified?: boolean; /** If true, collect all columns available from upstream sources for maximum search conditions */ upstream?: boolean; } /** * Represents a filterable item that can be used in DynamicQueryBuilder * Can be either a table column or a SQL parameter */ export declare class FilterableItem { readonly name: string; readonly type: 'column' | 'parameter'; readonly tableName?: string | undefined; constructor(name: string, type: 'column' | 'parameter', tableName?: string | undefined); } /** * Collects filterable items (columns and parameters) from SQL queries * for use in DynamicQueryBuilder filtering functionality. * * This class combines: * - Table columns (from SelectableColumnCollector with FullName duplicate detection) * - SQL parameters (from ParameterDetector) * * Features: * - FullName mode preserves columns with same names from different tables (u.id vs p.id) * - Upstream collection (default) provides comprehensive column discovery for maximum filtering * - Qualified mode option for table.column naming in complex JOINs * * This allows DynamicQueryBuilder to filter on both actual table columns * and fixed parameters defined in the SQL with full JOIN table support. */ export declare class FilterableItemCollector { private tableColumnResolver?; private options; /** * Creates a new FilterableItemCollector * @param tableColumnResolver Optional resolver for wildcard column expansion * @param options Optional configuration options * - qualified: If true, return table.column names; if false, return column names only * - upstream: If true (default), collect all available columns from upstream sources for maximum filtering capability */ constructor(tableColumnResolver?: TableColumnResolver, options?: FilterableItemCollectorOptions); /** * Collects all filterable items (columns and parameters) from a SQL query * @param query The parsed SQL query to analyze * @returns Array of FilterableItem objects representing columns and parameters */ collect(query: SelectQuery): FilterableItem[]; /** * Collects table columns using both SelectableColumnCollector and SchemaCollector */ private collectColumns; /** * Attempts to infer table name from query structure for simple cases */ private inferTableNameFromQuery; /** * Attempts to resolve real table name from alias/namespace */ private getRealTableName; /** * Extracts real table name from a datasource */ private extractRealTableName; /** * Collects SQL parameters from the query using ParameterDetector */ private collectParameters; /** * Removes duplicate items with the same name, type, and table name * This preserves columns with the same name from different tables */ private removeDuplicates; }