Skip to content
# Class: SelectQueryParser

Defined in: packages/core/src/parsers/SelectQueryParser.ts:33

Legacy SELECT-only parser. Prefer using SqlParser as the canonical entry point for multi-statement or mixed-statement workflows.

Constructors ​

Constructor ​

new SelectQueryParser(): SelectQueryParser

Returns ​

SelectQueryParser

Methods ​

parse() ​

static parse(query): SelectQuery

Defined in: packages/core/src/parsers/SelectQueryParser.ts:35

Parameters ​

query ​

string

Returns ​

SelectQuery


analyze() ​

static analyze(query): ParseAnalysisResult

Defined in: packages/core/src/parsers/SelectQueryParser.ts:88

Parameters ​

query ​

string

Returns ​

ParseAnalysisResult


parseAsync() ​

static parseAsync(query): Promise<SelectQuery&gt;

Defined in: packages/core/src/parsers/SelectQueryParser.ts:144

Asynchronously parse SQL string to AST. This method wraps the synchronous parse logic in a Promise for future extensibility.

Parameters ​

query ​

string

SQL string to parse

Returns ​

Promise<SelectQuery&gt;

Promise<SelectQuery>


parseFromLexeme() ​

static parseFromLexeme(lexemes, index): object

Defined in: packages/core/src/parsers/SelectQueryParser.ts:193

Parameters ​

lexemes ​

Lexeme[]

index ​

number

Returns ​

object

value ​

value: SelectQuery

newIndex ​

newIndex: number


getCursorCte() ​

static getCursorCte(sql, cursorPosition): string | null

Defined in: packages/core/src/parsers/SelectQueryParser.ts:633

Get the CTE name at the specified cursor position.

This method provides a simple interface for retrieving the CTE name based on a 1D cursor position in the SQL text.

Parameters ​

sql ​

string

The SQL string to analyze

cursorPosition ​

number

The cursor position (0-based character offset)

Returns ​

string | null

The CTE name if cursor is in a CTE, null otherwise

Deprecated ​

Use CTERegionDetector.getCursorCte() instead for better API consistency

Example ​

typescript
const sql = `WITH users AS (SELECT * FROM table) SELECT * FROM users`;
const cteName = SelectQueryParser.getCursorCte(sql, 25);
console.log(cteName); // "users"

getCursorCteAt() ​

static getCursorCteAt(sql, line, column): string | null

Defined in: packages/core/src/parsers/SelectQueryParser.ts:656

Get the CTE name at the specified 2D coordinates (line, column).

This method provides a convenient interface for editor integrations that work with line/column coordinates instead of character positions.

Parameters ​

sql ​

string

The SQL string to analyze

line ​

number

The line number (1-based)

column ​

number

The column number (1-based)

Returns ​

string | null

The CTE name if cursor is in a CTE, null otherwise

Deprecated ​

Use CTERegionDetector.getCursorCteAt() instead for better API consistency

Example ​

typescript
const sql = `WITH users AS (\n  SELECT * FROM table\n) SELECT * FROM users`;
const cteName = SelectQueryParser.getCursorCteAt(sql, 2, 5);
console.log(cteName); // "users"

positionToLineColumn() ​

static positionToLineColumn(text, position): { line: number; column: number; } | null

Defined in: packages/core/src/parsers/SelectQueryParser.ts:668

Convert character position to line/column coordinates.

Parameters ​

text ​

string

The text to analyze

position ​

number

The character position (0-based)

Returns ​

{ line: number; column: number; } | null

Object with line and column (1-based), or null if invalid position

Deprecated ​

Use CTERegionDetector.positionToLineColumn() instead for better API consistency

Released under the MIT License.