/** * @fileoverview SQL Logging Implementation for Generic Database Provider * * This module provides SQL statement logging functionality with file I/O, * filtering, formatting, and session management capabilities. It is * database-agnostic and shared between all platform-specific providers. * * @module @memberjunction/generic-database-provider/SqlLogger */ import { SQLDialect } from '@memberjunction/sql-dialect'; import { SqlLoggingOptions, SqlLoggingSession } from './types.js'; /** * Internal implementation of SqlLoggingSession that handles SQL statement logging to files. * This class manages file I/O, SQL formatting, and filtering based on session options. * * @internal */ export declare class SqlLoggingSessionImpl implements SqlLoggingSession { readonly id: string; readonly filePath: string; readonly startTime: Date; readonly options: SqlLoggingOptions; private _statementCount; private _emittedStatementCount; private _currentBatchVariableCount; private _fileHandle; private _disposed; private _compiledPatterns; private _dialect; /** * @param dialect - The SQL dialect to use for platform-specific SQL emission * (e.g. Flyway placeholder escaping, batch separators). Defaults to SQL * Server when not provided so existing callers and tests keep working * without immediately threading a dialect through every call site. */ constructor(id: string, filePath: string, options?: SqlLoggingOptions, dialect?: SQLDialect); /** * Gets the count of SQL statements actually written to the log file * @returns The number of emitted statements (after filtering) */ get statementCount(): number; /** * Initializes the logging session by creating the log file and writing the header * @throws Error if file creation fails */ initialize(): Promise; /** * Logs a SQL statement to the file, applying filtering and formatting based on session options * * @param query - The SQL query to log * @param parameters - Optional parameters for the query * @param description - Optional description for this operation * @param isMutation - Whether this is a data mutation operation * @param simpleSQLFallback - Optional simple SQL to use if logRecordChangeMetadata=false */ logSqlStatement(query: string, parameters?: unknown, description?: string, isMutation?: boolean, simpleSQLFallback?: string): Promise; /** * Disposes of the logging session, writes the footer, closes the file, and optionally deletes empty files */ dispose(): Promise; private _generateHeader; private _generateFooter; /** * Format SQL using sql-formatter library */ private _prettyPrintSql; /** * Post-process SQL to ensure BEGIN, END, and EXEC keywords are on their own lines. * Only applies transformations outside of SQL string literals to avoid corrupting * embedded SQL content stored in NVARCHAR fields. */ private _postProcessBeginEnd; /** * Splits SQL into alternating segments of non-literal text and string literals. * Handles SQL escaped quotes ('') within string literals correctly. * Also handles N-prefixed strings (N'...'). */ private _splitAroundStringLiterals; /** * Counts the number of SQL variable declarations in a statement. * Matches `@varName SQLTYPE` patterns that appear in DECLARE blocks (both the leading * `DECLARE @var TYPE` and continuation `@var TYPE` lines in multi-variable DECLAREs). * SET/EXEC parameter references are excluded because they have `=` or `,` after the var name, * not a type keyword. * * Used by the `variableBatchThreshold` logic to decide when to emit a batch separator. */ private _countVariableDeclarations; /** * Escapes ${...} patterns within SQL string literals to prevent Flyway from interpreting them as placeholders. * The actual escape form is platform-specific and delegated to the configured `SQLDialect` — see * `SQLDialect.EscapeFlywayStringInterpolation` for the rationale (NVARCHAR(4000) truncation on SQL Server, * different concat operator on PostgreSQL, etc.). */ private _escapeFlywaySyntaxInStrings; } //# sourceMappingURL=SqlLogger.d.ts.map