UNPKG

rawsql-ts

Version:

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

59 lines (58 loc) 2.34 kB
import { SqlComponent, SqlComponentVisitor } from '../models/SqlComponent'; import { TableColumnResolver } from './TableColumnResolver'; export declare class TableSchema { name: string; columns: string[]; constructor(name: string, columns: string[]); } /** * A visitor that collects schema information (table names and column names) from a SQL query structure. */ export declare class SchemaCollector implements SqlComponentVisitor<void> { private tableColumnResolver; private handlers; private tableSchemas; private visitedNodes; private commonTables; private running; constructor(tableColumnResolver?: TableColumnResolver | null); /** * Collects schema information (table names and column names) from a SQL query structure. * This method ensures that the collected schema information is unique and sorted. * The resulting schemas and columns are sorted alphabetically to ensure deterministic ordering. * * @param arg The SQL query structure to analyze. */ collect(arg: SqlComponent): TableSchema[]; /** * Main entry point for the visitor pattern. * Implements the shallow visit pattern to distinguish between root and recursive visits. * * This method ensures that schema information is collected uniquely and sorted. * The resulting schemas and columns are sorted alphabetically to ensure deterministic ordering. * * @param arg The SQL component to visit. */ visit(arg: SqlComponent): void; /** * Internal visit method used for all nodes. * This separates the visit flag management from the actual node visitation logic. */ private visitNode; /** * Resets the state of the collector for a new root visit. */ private reset; /** * Consolidates table schemas by merging columns for tables with the same name. * This ensures that each table name appears only once in the final schema list, * with all its columns combined while removing duplicates. * * Note: The resulting schemas and columns are sorted alphabetically to ensure deterministic ordering. */ private consolidateTableSchemas; private handleTableSource; private visitSimpleSelectQuery; private visitBinarySelectQuery; private processCollectTableSchema; }