pgsql-deparser
Version:
PostgreSQL AST Deparser
39 lines (38 loc) • 1.5 kB
TypeScript
import { RawStmt } from '@pgsql/types';
export interface ExtractedStatement {
statement: string;
index: number;
location?: number;
length?: number;
}
export interface StatementSplitterOptions {
/** Skip validation for malformed statements */
skipValidation?: boolean;
/** Strip leading comments from extracted statements */
stripComments?: boolean;
}
/**
* Extracts a single statement from SQL using PostgreSQL's location information.
* Handles Unicode properly by using byte positions instead of character positions.
*/
export declare function extractStatement(originalSQL: string, rawStmt: RawStmt, isFirst?: boolean, options?: StatementSplitterOptions): string | null;
/**
* Splits SQL text into individual statements using PostgreSQL's parser.
* Handles Unicode characters properly and provides detailed location information.
*/
export declare function splitStatements(sql: string, options?: StatementSplitterOptions): Promise<ExtractedStatement[]>;
/**
* Utility to generate statement keys for fixtures
*/
export declare function generateStatementKey(relativePath: string, statementIndex: number, extension?: string): string;
/**
* Test utility to compare byte vs character extraction for debugging Unicode issues
*/
export declare function debugUnicodeExtraction(sql: string, rawStmt: RawStmt): {
characterBased: string;
byteBased: string;
matches: boolean;
unicodeChars: number;
byteLength: number;
charLength: number;
};