UNPKG

rhombic

Version:

SQL parsing, lineage extraction and manipulation

57 lines 2.16 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ExtractTablesVisitor = void 0; const AbstractParseTreeVisitor_1 = require("antlr4ts/tree/AbstractParseTreeVisitor"); const common_1 = __importDefault(require("./common")); class ExtractTablesVisitor extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor { constructor(cursor) { super(); this.cursor = cursor; } defaultResult() { return { references: [], incomplete: [] }; } aggregateResult(aggregate, nextResult) { return { references: aggregate.references.concat(nextResult.references), incomplete: aggregate.incomplete.concat(nextResult.incomplete) }; } visitTableName(ctx) { const multipartTableName = ctx .multipartIdentifier() .errorCapturingIdentifier() .map(v => common_1.default.stripQuote(v.identifier()).name); const last = multipartTableName[multipartTableName.length - 1]; const cursor = this.cursor; if (cursor !== undefined) { if (cursor.isEqualTo(last)) { // cursor after dot const refs = multipartTableName.slice(0, -1).map(r => cursor.removeFrom(r)); return { references: [], incomplete: [{ references: refs }] }; } else { const refs = multipartTableName.map(r => cursor.removeFrom(r)); return { references: [common_1.default.tablePrimaryFromMultipart(refs)], incomplete: [] }; } } else { const refs = multipartTableName; return { references: [common_1.default.tablePrimaryFromMultipart(refs)], incomplete: [] }; } } } exports.ExtractTablesVisitor = ExtractTablesVisitor; //# sourceMappingURL=ExtractTablesVisitor.js.map