UNPKG

rawsql-ts

Version:

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

31 lines (30 loc) 1.38 kB
import { SelectQuery, SimpleSelectQuery } from "../models/SelectQuery"; /** * UpstreamSelectQueryFinder searches upstream queries for the specified columns. * If a query (including its upstream CTEs or subqueries) contains all columns, * it returns the highest such SelectQuery. Otherwise, it searches downstream. * For UNION queries, it checks each branch independently. */ export declare class UpstreamSelectQueryFinder { private options; private tableColumnResolver?; private columnCollector; constructor(tableColumnResolver?: (tableName: string) => string[], options?: { ignoreCaseAndUnderscore?: boolean; }); /** * Finds the highest SelectQuery containing all specified columns. * @param query The root SelectQuery to search. * @param columnNames A column name or array of column names to check for. * @returns An array of SelectQuery objects, or an empty array if not found. */ find(query: SelectQuery, columnNames: string | string[]): SimpleSelectQuery[]; private handleTableSource; private handleSubQuerySource; /** * Processes all source branches in a FROM clause and checks if all upstream queries contain the specified columns. * Returns a flat array of SelectQuery if all branches are valid, otherwise null. */ private processFromClauseBranches; private findUpstream; }