UNPKG

knex-dialect-athena

Version:
98 lines (96 loc) 3.58 kB
"use strict"; var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/athena-querycompiler.ts var athena_querycompiler_exports = {}; __export(athena_querycompiler_exports, { QueryCompiler_Athena: () => QueryCompiler_Athena }); module.exports = __toCommonJS(athena_querycompiler_exports); var import_querycompiler = __toESM(require("knex/lib/query/querycompiler")); var import_compact = __toESM(require("lodash/compact")); var components = [ "comments", "columns", "join", "where", "union", "group", "having", "order", "offset", "limit", // TODO: remove "lock", "waitMode" ]; var QueryCompiler_Athena = class extends import_querycompiler.default { // Compiles the `select` statement, or nested sub-selects by calling each of // the component compilers, trimming out the empties, and returning a // generated query string. select() { var _a; let sql = this.with(); let unionStatement = ""; const firstStatements = []; const endStatements = []; components.forEach((component) => { const statement = this[component](this); switch (component) { case "union": unionStatement = statement; break; case "comments": case "columns": case "join": case "where": firstStatements.push(statement); break; default: endStatements.push(statement); break; } }); const wrapMainQuery = (_a = this.grouped.union) == null ? void 0 : _a.map((u) => u.wrap).some((u) => u); if (this.onlyUnions()) { const statements = (0, import_compact.default)(firstStatements.concat(endStatements)).join( " " ); sql += unionStatement + (statements ? " " + statements : ""); } else { const allStatements = (wrapMainQuery ? "(" : "") + (0, import_compact.default)(firstStatements).join(" ") + (wrapMainQuery ? ")" : ""); const endStat = (0, import_compact.default)(endStatements).join(" "); sql += allStatements + (unionStatement ? " " + unionStatement : "") + (endStat ? " " + endStat : endStat); } return sql; } }; // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { QueryCompiler_Athena });