UNPKG

rawsql-ts

Version:

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

41 lines (40 loc) 1.45 kB
import { CommaBreakStyle, AndBreakStyle } from './SqlPrinter'; import { IndentCharOption, NewlineOption } from './LinePrinter'; import { SqlComponent } from '../models/SqlComponent'; export declare const VALID_PRESETS: readonly ["mysql", "postgres", "sqlserver", "sqlite"]; export type PresetName = (typeof VALID_PRESETS)[number]; /** * SqlFormatter class combines parsing and printing of SQL queries into a single interface. */ export declare class SqlFormatter { private parser; private printer; constructor(options?: { preset?: PresetName; identifierEscape?: { start: string; end: string; }; parameterSymbol?: string | { start: string; end: string; }; parameterStyle?: 'anonymous' | 'indexed' | 'named'; indentSize?: number; indentChar?: IndentCharOption; newline?: NewlineOption; keywordCase?: 'none' | 'upper' | 'lower'; commaBreak?: CommaBreakStyle; andBreak?: AndBreakStyle; }); /** * Formats a SQL query string with the given parameters. * @param sqlText The SQL query string to format. * @param parameters A dictionary of parameters to replace in the query. * @returns An object containing the formatted SQL string and the parameters. */ format(sql: SqlComponent): { formattedSql: string; params: Record<string, any>; }; }