UNPKG

rhombic

Version:

SQL parsing, lineage extraction and manipulation

64 lines 2.1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const SqlBaseParser_1 = require("./SqlBaseParser"); const common = { stripQuoteFromText(text, quote) { if (text.startsWith(quote) && text.endsWith(quote)) { return { name: text.substring(1, text.length - 1).replace(quote + quote, quote), quoted: true }; } else { return { name: text, quoted: false }; } }, stripQuote(ctx) { const strictId = ctx instanceof SqlBaseParser_1.StrictIdentifierContext ? ctx : ctx.strictIdentifier(); if (strictId !== undefined) { if (strictId instanceof SqlBaseParser_1.QuotedIdentifierAlternativeContext) { const quotedId = strictId.quotedIdentifier(); const [doubleQuotedId, backquotedId] = [quotedId.DOUBLEQUOTED_IDENTIFIER(), quotedId.BACKQUOTED_IDENTIFIER()]; if (doubleQuotedId !== undefined) { return common.stripQuoteFromText(doubleQuotedId.text, '"'); } else if (backquotedId !== undefined) { return common.stripQuoteFromText(backquotedId.text, "`"); } } } return { name: ctx.text, quoted: false }; }, tablePrimaryFromMultipart(names) { const len = names.length; if (len == 0) { throw new Error("Unexpected empty array for table name"); } else if (len == 1) { return { tableName: names[0] }; } else if (len == 2) { return { schemaName: names[0], tableName: names[1] }; } else { return { catalogName: names[len - 3], schemaName: names[len - 2], tableName: names[len - 1] }; } } }; exports.default = common; //# sourceMappingURL=common.js.map