rawsql-ts
Version:
[beta]High-performance SQL parser and AST analyzer written in TypeScript. Provides fast parsing and advanced transformation capabilities.
35 lines • 1.57 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.ReturningClauseParser = void 0;
// Provides parsing for RETURNING clauses in SQL (used in UPDATE, INSERT, DELETE, etc.)
const Lexeme_1 = require("../models/Lexeme");
const ValueComponent_1 = require("../models/ValueComponent");
const Clause_1 = require("../models/Clause");
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 === Lexeme_1.TokenType.Identifier) {
columns.push(new ValueComponent_1.IdentifierString(lexemes[idx].value));
idx++;
if (((_c = lexemes[idx]) === null || _c === void 0 ? void 0 : _c.type) === Lexeme_1.TokenType.Comma) {
idx++;
}
else {
break;
}
}
return { value: new Clause_1.ReturningClause(columns), newIndex: idx };
}
}
exports.ReturningClauseParser = ReturningClauseParser;
//# sourceMappingURL=ReturningClauseParser.js.map
;