UNPKG

@abaplint/transpiler

Version:
41 lines 1.92 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DatabaseSchemaReuse = void 0; class DatabaseSchemaReuse { myQuote; constructor(quote) { this.myQuote = quote; } quote(name) { return this.myQuote + name.toLowerCase() + this.myQuote; } buildVIEW(view) { const fields = view.getFields(); let firstTabname = ""; const columns = fields?.map((f) => { firstTabname = this.quote(f.TABNAME.toLowerCase()); return firstTabname + "." + f.FIELDNAME.toLowerCase() + " AS " + f.VIEWFIELD.toLowerCase(); }).join(", "); let from = ""; let previous = ""; for (const j of view.getJoin() || []) { if (previous === "") { from += this.quote(j.LTAB.toLowerCase()) + " INNER JOIN " + this.quote(j.RTAB.toLowerCase()) + " ON " + this.quote(j.LTAB.toLowerCase()) + "." + j.LFIELD.toLowerCase() + " = " + this.quote(j.RTAB.toLowerCase()) + "." + j.RFIELD.toLowerCase(); } else if (previous === j.LTAB + "," + j.RTAB) { from += " AND " + this.quote(j.LTAB.toLowerCase()) + "." + j.LFIELD.toLowerCase() + " = " + this.quote(j.RTAB.toLowerCase()) + "." + j.RFIELD.toLowerCase(); } else { from += " INNER JOIN " + this.quote(j.RTAB.toLowerCase()) + " ON " + this.quote(j.LTAB.toLowerCase()) + "." + j.LFIELD.toLowerCase() + " = " + this.quote(j.RTAB.toLowerCase()) + "." + j.RFIELD.toLowerCase(); } previous = j.LTAB + "," + j.RTAB; } from = from.trim(); if (from === "") { from = firstTabname; } return `CREATE VIEW ${this.quote(view.getName().toLowerCase())} AS SELECT ${columns} FROM ${from};\n`; } } exports.DatabaseSchemaReuse = DatabaseSchemaReuse; //# sourceMappingURL=_database_schema_reuse.js.map