/** * Statement-level SQL program AST. * * A `SqlProgram` is one parse of a SQL script into per-statement units, each * carrying its parsed node, semantic facts, source span, verbatim text, and a * dirty flag. Transformations mutate a statement's `stmt` node and mark it * dirty; emission re-prints only dirty statements through the deparser and * copies every other byte of the script verbatim (comments, whitespace, * untouched statements). A program with no dirty statements emits its source * byte-identically, so content-addressed hashes are preserved. */ import type { StatementFacts } from '@pgsql/semantics'; /** A statement's location in the source script (byte offsets). */ export type SqlStatementSpan = StatementFacts['span']; /** One statement of a parsed SQL script. */ export interface SqlStatementAst { /** The tagged statement node (e.g. `{ CreateStmt: {...} }`), mutable. */ stmt: any; /** Semantic facts classified from the statement. */ facts: StatementFacts; /** Source span within the program's `source`. */ span: SqlStatementSpan; /** Verbatim source text of the statement (`source.slice(start, start+len)`). */ raw: string; /** Whether the statement's AST has been mutated and must be deparsed. */ dirty: boolean; } /** A SQL script parsed once into statement units. */ export interface SqlProgram { source: string; statements: SqlStatementAst[]; } /** * Parse a SQL script into a statement program. Requires `loadModule()` from * `plpgsql-parser` to have completed. */ export declare function parseSqlProgram(source: string): SqlProgram; /** * Emit a program back to SQL. Clean statements — and every byte between * statements — are copied verbatim from the source; dirty statements are * re-printed through the deparser. With no dirty statements the output is * byte-identical to the source. */ export declare function emitSqlProgram(program: SqlProgram): string;