UNPKG

rawsql-ts

Version:

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

31 lines 1.37 kB
// Provides parsing for RETURNING clauses in SQL (used in UPDATE, INSERT, DELETE, etc.) import { TokenType } from "../models/Lexeme"; import { IdentifierString } from "../models/ValueComponent"; import { ReturningClause } from "../models/Clause"; export class ReturningClauseParser { /** * Parse RETURNING clause from lexemes, starting at the given index. * Returns a ReturningClause instance and the new index after parsing. */ static parseFromLexeme(lexemes, index) { var _a, _b, _c; let idx = index; if (((_a = lexemes[idx]) === null || _a === void 0 ? void 0 : _a.value) !== "returning") { throw new Error(`Syntax error at position ${idx}: Expected 'RETURNING' but found '${(_b = lexemes[idx]) === null || _b === void 0 ? void 0 : _b.value}'.`); } idx++; const columns = []; while (idx < lexemes.length && lexemes[idx].type === TokenType.Identifier) { columns.push(new IdentifierString(lexemes[idx].value)); idx++; if (((_c = lexemes[idx]) === null || _c === void 0 ? void 0 : _c.type) === TokenType.Comma) { idx++; } else { break; } } return { value: new ReturningClause(columns), newIndex: idx }; } } //# sourceMappingURL=ReturningClauseParser.js.map