/** * One SQL scanner, shared by everything in the migrate pipeline that has to * reason about statement boundaries. * * There were two hand-rolled splitters before this, and they disagreed. The * runner (`parseStatements`) learned string literals and dollar-quoted bodies * in #317 so a plpgsql function body would survive; the safety gate kept a * `sql.split(';')` that then discarded any fragment starting with `--`. Since * a statement and the comment above it land in the *same* fragment, the gate * dropped comment-led statements entirely and reported migrations clean that * dropped tables (#334). Neither splitter knew about block comments or quoted * identifiers. * * The rules, in one place: * * - `--` runs to end of line; block comments nest, per Postgres. * - Comments are removed, replaced by whitespace so they still separate tokens. * - `'…'`, `"…"` and `$tag$…$tag$` are copied verbatim — a `;` or `--` inside * them is content, not syntax. Backslash escapes apply only in `E'…'`. * - Comment state and quote state are decided in the same pass. That ordering * is load-bearing: an apostrophe in a comment (`-- the migration's ancestors`) * must not open a string literal, and a `--` inside a literal must not open * a comment. Either check running first, alone, gets the other case wrong. * - An unterminated comment or literal runs to end of input; the SQL is invalid * either way and Postgres is what should say so. */ export interface ScanOptions { /** * Honor drizzle's `--> statement-breakpoint` as an explicit statement * separator. The runner needs this (it decides what is sent to Postgres as * one statement); the safety gate does not care. */ breakpointSeparator?: boolean; } /** Splits SQL into statements, stripping comments. */ export declare function scanStatements(sql: string, options?: ScanOptions): string[]; /** * Removes comments, leaving literals and dollar-quoted bodies intact and * statement separators where they were. For callers that need to test SQL * against a pattern without a comment supplying a false match or hiding a * real one. */ export declare function stripComments(sql: string): string; /** * Replaces the *contents* of `'…'` string literals with spaces, keeping the * quotes and the overall length. * * A string literal in a migration is data — `INSERT INTO notes VALUES * ('a; DROP TABLE x')` drops nothing. Matching hazard rules against literal * text raises a hazard for inert seed data, and no amount of pattern-tuning * fixes that, because "is this text dangerous" is not answerable from the * text. What makes a literal dangerous is `EXECUTE` running it, which is a * structural fact and gets its own rule. * * Dollar-quoted bodies are deliberately NOT blanked: `DO $$ BEGIN DROP TABLE * x; END $$` is code, and it executes during the migration. */ export declare function blankLiterals(sql: string): string; /** * Index of the first character of actual SQL in `sql` — i.e. past any leading * whitespace and comments. Lets a text rewriter skip a leading comment block * without rewriting words inside it. */ export declare function codeStartOffset(sql: string): number; //# sourceMappingURL=statements.d.ts.map