rawsql-ts
Version:
[beta]High-performance SQL parser and AST analyzer written in TypeScript. Provides fast parsing and advanced transformation capabilities.
84 lines (83 loc) • 3.75 kB
TypeScript
import { SqlComponent } from '../models/SqlComponent';
/**
* Utility class for editing comments on SQL components.
* Provides functions to add, edit, delete, and search comments in SQL AST.
*/
export declare class CommentEditor {
/**
* Add a comment to a SQL component
* For SelectQuery components, adds to headerComments for query-level comments
* @param component The SQL component to add comment to
* @param comment The comment text to add
*/
static addComment(component: SqlComponent, comment: string): void;
/**
* Check if a component implements SelectQuery interface
* Uses discriminator property for robust type detection
* @param component The component to check
* @returns true if the component is a SelectQuery
*/
private static isSelectQuery;
/**
* Edit an existing comment by index
* For SelectQuery components, edits headerComments
* @param component The SQL component containing the comment
* @param index The index of the comment to edit (0-based)
* @param newComment The new comment text
* @throws Error if index is invalid
*/
static editComment(component: SqlComponent, index: number, newComment: string): void;
/**
* Delete a comment by index
* For SelectQuery components, deletes from headerComments
* @param component The SQL component containing the comment
* @param index The index of the comment to delete (0-based)
* @throws Error if index is invalid
*/
static deleteComment(component: SqlComponent, index: number): void;
/**
* Delete all comments from a component
* @param component The SQL component to clear comments from
*/
static deleteAllComments(component: SqlComponent): void;
/**
* Get all comments from a component
* For SelectQuery components, returns headerComments instead of regular comments
* @param component The SQL component to get comments from
* @returns Array of comment strings (empty array if no comments)
*/
static getComments(component: SqlComponent): string[];
/**
* Find all components in the AST that have comments containing the search text
* @param root The root SQL component to search from
* @param searchText The text to search for in comments
* @param caseSensitive Whether the search should be case-sensitive (default: false)
* @returns Array of components that have matching comments
*/
static findComponentsWithComment(root: SqlComponent, searchText: string, caseSensitive?: boolean): SqlComponent[];
/**
* Replace all occurrences of a text in comments across the entire AST
* @param root The root SQL component to search and replace in
* @param searchText The text to search for
* @param replaceText The text to replace with
* @param caseSensitive Whether the search should be case-sensitive (default: false)
* @returns Number of replacements made
*/
static replaceInComments(root: SqlComponent, searchText: string, replaceText: string, caseSensitive?: boolean): number;
/**
* Count total number of comments in the AST
* @param root The root SQL component to count comments in
* @returns Total number of comments
*/
static countComments(root: SqlComponent): number;
/**
* Get all comments from the entire AST as a flat array with their source components
* @param root The root SQL component to extract comments from
* @returns Array of objects containing comment text and the component they belong to
*/
static getAllComments(root: SqlComponent): {
comment: string;
component: SqlComponent;
index: number;
}[];
}