UNPKG

node-sql-parser

Version:
1 lines 2.54 MB
!function(r,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var e=t();for(var n in e)("object"==typeof exports?exports:r)[n]=e[n]}}(this,(function(){return function(r){var t={};function e(n){if(t[n])return t[n].exports;var s=t[n]={i:n,l:!1,exports:{}};return r[n].call(s.exports,s,s.exports,e),s.l=!0,s.exports}return e.m=r,e.c=t,e.d=function(r,t,n){e.o(r,t)||Object.defineProperty(r,t,{enumerable:!0,get:n})},e.r=function(r){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(r,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(r,"__esModule",{value:!0})},e.t=function(r,t){if(1&t&&(r=e(r)),8&t)return r;if(4&t&&"object"==typeof r&&r&&r.__esModule)return r;var n=Object.create(null);if(e.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:r}),2&t&&"string"!=typeof r)for(var s in r)e.d(n,s,function(t){return r[t]}.bind(null,s));return n},e.n=function(r){var t=r&&r.__esModule?function(){return r.default}:function(){return r};return e.d(t,"a",t),t},e.o=function(r,t){return Object.prototype.hasOwnProperty.call(r,t)},e.p="",e(e.s=41)}([function(r,t,e){"use strict";e.r(t),e.d(t,"arrayStructTypeToSQL",(function(){return O})),e.d(t,"autoIncrementToSQL",(function(){return S})),e.d(t,"columnOrderListToSQL",(function(){return _})),e.d(t,"commonKeywordArgsToSQL",(function(){return g})),e.d(t,"commonOptionConnector",(function(){return i})),e.d(t,"connector",(function(){return l})),e.d(t,"commonTypeValue",(function(){return E})),e.d(t,"commentToSQL",(function(){return I})),e.d(t,"createBinaryExpr",(function(){return f})),e.d(t,"createValueExpr",(function(){return c})),e.d(t,"dataTypeToSQL",(function(){return T})),e.d(t,"DEFAULT_OPT",(function(){return u})),e.d(t,"escape",(function(){return b})),e.d(t,"literalToSQL",(function(){return h})),e.d(t,"columnIdentifierToSql",(function(){return C})),e.d(t,"getParserOpt",(function(){return v})),e.d(t,"identifierToSql",(function(){return d})),e.d(t,"onPartitionsToSQL",(function(){return m})),e.d(t,"replaceParams",(function(){return A})),e.d(t,"returningToSQL",(function(){return N})),e.d(t,"hasVal",(function(){return y})),e.d(t,"setParserOpt",(function(){return p})),e.d(t,"toUpper",(function(){return w})),e.d(t,"topToSQL",(function(){return L})),e.d(t,"triggerEventToSQL",(function(){return R}));var n=e(2),s=e(8);function o(r){return(o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(r){return typeof r}:function(r){return r&&"function"==typeof Symbol&&r.constructor===Symbol&&r!==Symbol.prototype?"symbol":typeof r})(r)}var u={database:"mysql",type:"table",trimQuery:!0,parseOptions:{includeLocations:!1}},a=u;function i(r,t,e){if(e)return r?"".concat(r.toUpperCase()," ").concat(t(e)):t(e)}function l(r,t){if(t)return"".concat(r.toUpperCase()," ").concat(t)}function c(r){var t=o(r);if(Array.isArray(r))return{type:"expr_list",value:r.map(c)};if(null===r)return{type:"null",value:null};switch(t){case"boolean":return{type:"bool",value:r};case"string":return{type:"string",value:r};case"number":return{type:"number",value:r};default:throw new Error('Cannot convert value "'.concat(t,'" to SQL'))}}function f(r,t,e){var n={operator:r,type:"binary_expr"};return n.left=t.type?t:c(t),"BETWEEN"===r||"NOT BETWEEN"===r?(n.right={type:"expr_list",value:[c(e[0]),c(e[1])]},n):(n.right=e.type?e:c(e),n)}function b(r){return r}function v(){return a}function p(r){a=r}function L(r){if(r){var t=r.value,e=r.percent,n=r.parentheses?"(".concat(t,")"):t,s="TOP ".concat(n);return e?"".concat(s," ").concat(e.toUpperCase()):s}}function C(r){var t=v().database;if(r)switch(t&&t.toLowerCase()){case"athena":case"db2":case"postgresql":case"redshift":case"snowflake":case"noql":case"trino":case"sqlite":return'"'.concat(r,'"');case"transactsql":return"[".concat(r,"]");case"mysql":case"mariadb":case"bigquery":default:return"`".concat(r,"`")}}function d(r,t,e){if(!0===t)return"'".concat(r,"'");if(r){if("*"===r)return r;if(null!=e)return"".concat(e).concat(r).concat(e);var n=v().database;switch(n&&n.toLowerCase()){case"mysql":case"mariadb":return"`".concat(r,"`");case"athena":case"postgresql":case"redshift":case"snowflake":case"trino":case"noql":case"sqlite":return'"'.concat(r,'"');case"transactsql":return"[".concat(r,"]");case"bigquery":case"db2":return r;default:return"`".concat(r,"`")}}}function w(r){if(r)return r.toUpperCase()}function y(r){return r}function h(r){if(r){var t=r.prefix,e=r.type,n=r.parentheses,u=r.suffix,a=r.value,i="object"===o(r)?a:r;switch(e){case"backticks_quote_string":i="`".concat(a,"`");break;case"string":i="'".concat(a,"'");break;case"regex_string":i='r"'.concat(a,'"');break;case"hex_string":i="X'".concat(a,"'");break;case"full_hex_string":i="0x".concat(a);break;case"natural_string":i="N'".concat(a,"'");break;case"bit_string":i="b'".concat(a,"'");break;case"double_quote_string":i='"'.concat(a,'"');break;case"single_quote_string":i="'".concat(a,"'");break;case"boolean":case"bool":i=a?"TRUE":"FALSE";break;case"null":i="NULL";break;case"star":i="*";break;case"param":i="".concat(t||":").concat(a),t=null;break;case"origin":i=a.toUpperCase();break;case"date":case"datetime":case"time":case"timestamp":i="".concat(e.toUpperCase()," '").concat(a,"'");break;case"var_string":i="N'".concat(a,"'");break;case"unicode_string":i="U&'".concat(a,"'")}var l=[];return t&&l.push(w(t)),l.push(i),u&&("string"==typeof u&&l.push(u),"object"===o(u)&&(u.collate?l.push(Object(s.a)(u.collate)):l.push(h(u)))),i=l.join(" "),n?"(".concat(i,")"):i}}function E(r){if(!r)return[];var t=r.type,e=r.symbol,n=r.value;return[t.toUpperCase(),e,"string"==typeof n?n.toUpperCase():h(n)].filter(y)}function A(r,t){return function r(t,e){return Object.keys(t).filter((function(r){var e=t[r];return Array.isArray(e)||"object"===o(e)&&null!==e})).forEach((function(n){var s=t[n];if("object"!==o(s)||"param"!==s.type)return r(s,e);if(void 0===e[s.value])throw new Error("no value for parameter :".concat(s.value," found"));return t[n]=c(e[s.value]),null})),t}(JSON.parse(JSON.stringify(r)),t)}function m(r){var t=r.type,e=r.partitions;return[w(t),"(".concat(e.map((function(r){if("range"!==r.type)return h(r);var t=r.start,e=r.end,n=r.symbol;return"".concat(h(t)," ").concat(w(n)," ").concat(h(e))})).join(", "),")")].join(" ")}function T(r){var t=r.schema,e=r.dataType,n=r.length,s=r.parentheses,o=r.scale,u=r.suffix,a="";null!=n&&(a=o?"".concat(n,", ").concat(o):n),s&&(a="(".concat(a,")")),u&&u.length&&(a+=" ".concat(u.join(" ")));var i=t?"".concat(t,"."):"";return"".concat(i).concat(e).concat(a)}function O(r){if(r){var t=r.dataType,e=r.definition,n=r.anglebracket,s=w(t);if("ARRAY"!==s&&"STRUCT"!==s)return s;var o=e&&e.map((function(r){return[r.field_name,O(r.field_type)].filter(y).join(" ")})).join(", ");return n?"".concat(s,"<").concat(o,">"):"".concat(s," ").concat(o)}}function I(r){if(r){var t=[],e=r.keyword,n=r.symbol,s=r.value;return t.push(e.toUpperCase()),n&&t.push(n),t.push(h(s)),t.join(" ")}}function R(r){return r.map((function(r){var t=r.keyword,e=r.args,s=[w(t)];if(e){var o=e.keyword,u=e.columns;s.push(w(o),u.map(n.f).join(", "))}return s.join(" ")})).join(" OR ")}function N(r){return r?["RETURNING",r.columns.map(n.h).filter(y).join(", ")].join(" "):""}function g(r){return r?[w(r.keyword),w(r.args)]:[]}function S(r){if(r){if("string"==typeof r){var t=v().database;switch(t&&t.toLowerCase()){case"sqlite":return"AUTOINCREMENT";default:return"AUTO_INCREMENT"}}var e=r.keyword,n=r.seed,s=r.increment,o=r.parentheses,u=w(e);return o&&(u+="(".concat(h(n),", ").concat(h(s),")")),u}}function _(r){if(r)return r.map(n.e).filter(y).join(", ")}},function(r,t,e){"use strict";e.d(t,"a",(function(){return I})),e.d(t,"b",(function(){return R})),e.d(t,"d",(function(){return O})),e.d(t,"c",(function(){return N}));var n=e(0),s=e(11),o=e(16);var u=e(24),a=e(22);var i=e(8),l=e(2),c=e(6),f=e(12),b=e(19);var v=e(14),p=e(25),L=e(9);function C(r){return(C="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(r){return typeof r}:function(r){return r&&"function"==typeof Symbol&&r.constructor===Symbol&&r!==Symbol.prototype?"symbol":typeof r})(r)}function d(r){var t=r.expr_list,e=r.type;switch(Object(n.toUpper)(e)){case"STRUCT":case"ROW":return"(".concat(Object(l.i)(t),")");case"ARRAY":return function(r){var t=r.array_path,e=r.brackets,s=r.expr_list,o=r.parentheses;if(!s)return"[".concat(Object(l.i)(t),"]");var u=Array.isArray(s)?s.map((function(r){return"(".concat(Object(l.i)(r),")")})).filter(n.hasVal).join(", "):I(s);return e?"[".concat(u,"]"):o?"(".concat(u,")"):u}(r);default:return""}}function w(r){var t=r.definition,e=r.keyword,s=r.orderby,o=r.limit,u=[Object(n.toUpper)(e)];return t&&"object"===C(t)&&(u.length=0,u.push(Object(n.arrayStructTypeToSQL)(t))),u.push(d(r),N(s,"order by"),Object(L.a)(o)),u.filter(n.hasVal).join("")}var y=e(23),h=e(3),E=e(5),A=e(21);function m(r){return(m="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(r){return typeof r}:function(r){return r&&"function"==typeof Symbol&&r.constructor===Symbol&&r!==Symbol.prototype?"symbol":typeof r})(r)}var T={alter:s.b,aggr_func:function(r){var t=r.args,e=r.filter,s=r.over,u=r.within_group_orderby,a=I(t.expr);a=Array.isArray(a)?a.join(", "):a;var i=r.name,l=Object(o.a)(s);t.distinct&&(a=["DISTINCT",a].join(" ")),t.separator&&t.separator.delimiter&&(a=[a,Object(n.literalToSQL)(t.separator.delimiter)].join("".concat(t.separator.symbol," "))),t.separator&&t.separator.expr&&(a=[a,I(t.separator.expr)].join(" ")),t.orderby&&(a=[a,N(t.orderby,"order by")].join(" ")),t.separator&&t.separator.value&&(a=[a,Object(n.toUpper)(t.separator.keyword),Object(n.literalToSQL)(t.separator.value)].filter(n.hasVal).join(" "));var c=u?"WITHIN GROUP (".concat(N(u,"order by"),")"):"",f=e?"FILTER (WHERE ".concat(I(e.where),")"):"";return["".concat(i,"(").concat(a,")"),c,l,f].filter(n.hasVal).join(" ")},any_value:c.a,window_func:A.c,array:w,assign:u.a,binary_expr:a.a,case:function(r){var t=["CASE"],e=r.args,n=r.expr,s=r.parentheses;n&&t.push(I(n));for(var o=0,u=e.length;o<u;++o)t.push(e[o].type.toUpperCase()),e[o].cond&&(t.push(I(e[o].cond)),t.push("THEN")),t.push(I(e[o].result));return t.push("END"),s?"(".concat(t.join(" "),")"):t.join(" ")},cast:c.c,collate:i.a,column_ref:l.f,column_definition:l.c,datatype:n.dataTypeToSQL,extract:c.d,flatten:c.e,fulltext_search:l.j,function:c.g,lambda:c.i,load_data:y.a,insert:E.b,interval:b.a,json:function(r){var t=r.keyword,e=r.expr_list;return[Object(n.toUpper)(t),e.map((function(r){return I(r)})).join(", ")].join(" ")},json_object_arg:c.h,json_visitor:function(r){return[r.symbol,I(r.expr)].join("")},func_arg:c.f,show:p.a,struct:w,tablefunc:c.j,tables:h.c,unnest:h.d,values:f.c,window:A.b};function O(r){var t=r.prefix,e=void 0===t?"@":t,s=r.name,o=r.members,u=r.quoted,a=r.suffix,i=[],l=o&&o.length>0?"".concat(s,".").concat(o.join(".")):s,c="".concat(e||"").concat(l);return a&&(c+=a),i.push(c),[u,i.join(" "),u].filter(n.hasVal).join("")}function I(r){if(r){var t=r;if(r.ast){var e=t.ast;Reflect.deleteProperty(t,e);for(var s=0,o=Object.keys(e);s<o.length;s++){var u=o[s];t[u]=e[u]}}var a=t.type;return"expr"===a?I(t.expr):T[a]?T[a](t):Object(n.literalToSQL)(t)}}function R(r){return r?(Array.isArray(r)||(r=[r]),r.map(I)):[]}function N(r,t){if(!Array.isArray(r))return"";var e=[],s=Object(n.toUpper)(t);switch(s){case"ORDER BY":e=r.map((function(r){return[I(r.expr),r.type||"ASC",Object(n.toUpper)(r.nulls)].filter(n.hasVal).join(" ")}));break;case"PARTITION BY":default:e=r.map((function(r){return I(r.expr)}))}return Object(n.connector)(s,e.join(", "))}T.var=O,T.expr_list=function(r){var t=R(r.value),e=r.parentheses,n=r.separator;if(!e&&!n)return t;var s=n||", ",o=t.join(s);return e?"(".concat(o,")"):o},T.select=function(r){var t="object"===m(r._next)?Object(E.b)(r):Object(v.a)(r);return r.parentheses?"(".concat(t,")"):t},T.unary_expr=function(r){var t=r.operator,e=r.parentheses,n=r.expr,s="-"===t||"+"===t||"~"===t||"!"===t?"":" ",o="".concat(t).concat(s).concat(I(n));return e?"(".concat(o,")"):o},T.map_object=function(r){var t=r.keyword,e=r.expr.map((function(r){return[Object(n.literalToSQL)(r.key),Object(n.literalToSQL)(r.value)].join(", ")})).join(", ");return[Object(n.toUpper)(t),"[".concat(e,"]")].join("")}},function(r,t,e){"use strict";e.d(t,"a",(function(){return d})),e.d(t,"c",(function(){return m})),e.d(t,"f",(function(){return w})),e.d(t,"h",(function(){return I})),e.d(t,"i",(function(){return N})),e.d(t,"b",(function(){return y})),e.d(t,"d",(function(){return C})),e.d(t,"e",(function(){return A})),e.d(t,"g",(function(){return h})),e.d(t,"j",(function(){return O})),e.d(t,"k",(function(){return R}));var n=e(8),s=e(20),o=e(1),u=e(6),a=e(3),i=e(0);function l(r){return(l="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(r){return typeof r}:function(r){return r&&"function"==typeof Symbol&&r.constructor===Symbol&&r!==Symbol.prototype?"symbol":typeof r})(r)}function c(r,t){var e=Object.keys(r);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(r);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(r,t).enumerable}))),e.push.apply(e,n)}return e}function f(r){for(var t=1;t<arguments.length;t++){var e=null!=arguments[t]?arguments[t]:{};t%2?c(Object(e),!0).forEach((function(t){b(r,t,e[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(e)):c(Object(e)).forEach((function(t){Object.defineProperty(r,t,Object.getOwnPropertyDescriptor(e,t))}))}return r}function b(r,t,e){return(t=function(r){var t=function(r,t){if("object"!=l(r)||!r)return r;var e=r[Symbol.toPrimitive];if(void 0!==e){var n=e.call(r,t||"default");if("object"!=l(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(r)}(r,"string");return"symbol"==l(t)?t:t+""}(t))in r?Object.defineProperty(r,t,{value:e,enumerable:!0,configurable:!0,writable:!0}):r[t]=e,r}function v(r){return function(r){if(Array.isArray(r))return L(r)}(r)||function(r){if("undefined"!=typeof Symbol&&null!=r[Symbol.iterator]||null!=r["@@iterator"])return Array.from(r)}(r)||p(r)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function p(r,t){if(r){if("string"==typeof r)return L(r,t);var e={}.toString.call(r).slice(8,-1);return"Object"===e&&r.constructor&&(e=r.constructor.name),"Map"===e||"Set"===e?Array.from(r):"Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e)?L(r,t):void 0}}function L(r,t){(null==t||t>r.length)&&(t=r.length);for(var e=0,n=Array(t);e<t;e++)n[e]=r[e];return n}function C(r,t){if("string"==typeof r)return Object(i.identifierToSql)(r,t);var e=r.expr,n=r.offset,s=r.suffix,u=n&&n.map((function(r){return["[",r.name,"".concat(r.name?"(":""),Object(i.literalToSQL)(r.value),"".concat(r.name?")":""),"]"].filter(i.hasVal).join("")})).join("");return[Object(o.a)(e),u,s].filter(i.hasVal).join("")}function d(r){if(!r||0===r.length)return"";var t,e=[],n=function(r,t){var e="undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(!e){if(Array.isArray(r)||(e=p(r))||t&&r&&"number"==typeof r.length){e&&(r=e);var n=0,s=function(){};return{s:s,n:function(){return n>=r.length?{done:!0}:{done:!1,value:r[n++]}},e:function(r){throw r},f:s}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,u=!0,a=!1;return{s:function(){e=e.call(r)},n:function(){var r=e.next();return u=r.done,r},e:function(r){a=!0,o=r},f:function(){try{u||null==e.return||e.return()}finally{if(a)throw o}}}}(r);try{for(n.s();!(t=n.n()).done;){var s=t.value,u=s.brackets?"[".concat(Object(o.a)(s.index),"]"):"".concat(s.notation).concat(Object(o.a)(s.index));s.property&&(u="".concat(u,".").concat(Object(i.literalToSQL)(s.property))),e.push(u)}}catch(r){n.e(r)}finally{n.f()}return e.join("")}function w(r){var t=r.array_index,e=r.as,s=r.column,u=r.collate,a=r.db,l=r.isDual,c=r.notations,f=void 0===c?[]:c,b=r.options,p=r.schema,L=r.table,w=r.parentheses,y=r.suffix,h=r.order_by,E=r.subFields,A=void 0===E?[]:E,m="*"===s?"*":C(s,l),T=[a,p,L].filter(i.hasVal).map((function(r){return"".concat("string"==typeof r?Object(i.identifierToSql)(r):Object(o.a)(r))})),O=T[0];if(O){for(var I=1;I<T.length;++I)O="".concat(O).concat(f[I]||".").concat(T[I]);m="".concat(O).concat(f[I]||".").concat(m)}var R=[m=["".concat(m).concat(d(t))].concat(v(A)).join("."),Object(n.a)(u),Object(o.a)(b),Object(i.commonOptionConnector)("AS",o.a,e)];R.push("string"==typeof y?Object(i.toUpper)(y):Object(o.a)(y)),R.push(Object(i.toUpper)(h));var N=R.filter(i.hasVal).join(" ");return w?"(".concat(N,")"):N}function y(r){if(r){var t=r.schema,e=r.dataType,n=r.length,s=r.suffix,a=r.scale,l=r.expr,c=null!=n,f=Object(i.dataTypeToSQL)({schema:t,dataType:e,length:n,suffix:s,scale:a,parentheses:c});if(l&&(f+=Object(o.a)(l)),r.array){var b=Object(u.b)(r);f+=[/^\[.*\]$/.test(b)?"":" ",b].join("")}return f}}function h(r){var t=[];if(!r)return t;var e=r.definition,n=r.keyword,s=r.match,u=r.table,l=r.on_action;return t.push(Object(i.toUpper)(n)),t.push(Object(a.c)(u)),t.push(e&&"(".concat(e.map((function(r){return Object(o.a)(r)})).join(", "),")")),t.push(Object(i.toUpper)(s)),l.map((function(r){return t.push(Object(i.toUpper)(r.type),Object(o.a)(r.value))})),t.filter(i.hasVal)}function E(r){var t=[],e=r.nullable,n=r.character_set,u=r.check,a=r.comment,l=r.constraint,c=r.collate,f=r.storage,b=r.using,p=r.default_val,L=r.generated,C=r.auto_increment,d=r.unique,w=r.primary_key,y=r.column_format,E=r.reference_definition,A=r.generated_by_default,m=[Object(i.toUpper)(e&&e.action),Object(i.toUpper)(e&&e.value)].filter(i.hasVal).join(" ");if(L||t.push(m),p){var T=p.type,O=p.value;t.push(T.toUpperCase(),Object(o.a)(O))}var I=Object(i.getParserOpt)().database;return l&&t.push(Object(i.toUpper)(l.keyword),Object(i.literalToSQL)(l.constraint)),t.push(Object(s.a)(u)),t.push(function(r){if(r)return[Object(i.toUpper)(r.value),"(".concat(Object(o.a)(r.expr),")"),Object(i.toUpper)(r.storage_type)].filter(i.hasVal).join(" ")}(L)),L&&t.push(m),t.push(Object(i.autoIncrementToSQL)(C),Object(i.toUpper)(w),Object(i.toUpper)(d),Object(i.literalToSQL)(A),Object(i.commentToSQL)(a)),t.push.apply(t,v(Object(i.commonTypeValue)(n))),"sqlite"!==I.toLowerCase()&&t.push(Object(o.a)(c)),t.push.apply(t,v(Object(i.commonTypeValue)(y))),t.push.apply(t,v(Object(i.commonTypeValue)(f))),t.push.apply(t,v(h(E))),t.push(Object(i.commonOptionConnector)("USING",o.a,b)),t.filter(i.hasVal).join(" ")}function A(r){var t=r.order_by,e=r.column,n=r.collate,s=r.nulls,u=r.opclass,a="string"==typeof e?{type:"column_ref",table:r.table,column:e}:f(f({},r),{},{order_by:null});return a.collate=null,[Object(o.a)(a),Object(o.a)(n),u,Object(i.toUpper)(t),Object(i.toUpper)(s)].filter(i.hasVal).join(" ")}function m(r){var t=[],e=w(r.column),n=y(r.definition);return t.push(e),t.push(n),t.push(E(r)),t.filter(i.hasVal).join(" ")}function T(r){return r?"object"===l(r)?["AS",Object(o.a)(r)].join(" "):["AS",/^(`?)[a-z_][0-9a-z_]*(`?)$/i.test(r)?Object(i.identifierToSql)(r):Object(i.columnIdentifierToSql)(r)].join(" "):""}function O(r){var t=r.against,e=r.as,n=r.columns,s=r.match,u=r.mode;return[[Object(i.toUpper)(s),"(".concat(n.map((function(r){return w(r)})).join(", "),")")].join(" "),[Object(i.toUpper)(t),["(",Object(o.a)(r.expr),u&&" ".concat(Object(i.literalToSQL)(u)),")"].filter(i.hasVal).join("")].join(" "),T(e)].filter(i.hasVal).join(" ")}function I(r,t){var e=r.expr,n=r.type;if("cast"===n)return Object(u.c)(r);t&&(e.isDual=t);var s=Object(o.a)(e),a=r.expr_list;if(a){var l=[s],c=a.map((function(r){return I(r,t)})).join(", ");return l.push([Object(i.toUpper)(n),n&&"(",c,n&&")"].filter(i.hasVal).join("")),l.filter(i.hasVal).join(" ")}return e.parentheses&&Reflect.has(e,"array_index")&&"cast"!==e.type&&(s="(".concat(s,")")),e.array_index&&"column_ref"!==e.type&&"function"!==e.type&&(s="".concat(s).concat(d(e.array_index))),[s,T(r.as)].filter(i.hasVal).join(" ")}function R(r){var t=Array.isArray(r)&&r[0];return!(!t||"dual"!==t.type)}function N(r,t){if(!r||"*"===r)return r;var e=R(t);return r.map((function(r){return I(r,e)})).join(", ")}},function(r,t,e){"use strict";e.d(t,"c",(function(){return d})),e.d(t,"a",(function(){return w})),e.d(t,"b",(function(){return C})),e.d(t,"d",(function(){return f}));var n=e(22),s=e(2),o=e(1),u=e(12),a=e(19),i=e(0);function l(r){return function(r){if(Array.isArray(r))return c(r)}(r)||function(r){if("undefined"!=typeof Symbol&&null!=r[Symbol.iterator]||null!=r["@@iterator"])return Array.from(r)}(r)||function(r,t){if(r){if("string"==typeof r)return c(r,t);var e={}.toString.call(r).slice(8,-1);return"Object"===e&&r.constructor&&(e=r.constructor.name),"Map"===e||"Set"===e?Array.from(r):"Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e)?c(r,t):void 0}}(r)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function c(r,t){(null==t||t>r.length)&&(t=r.length);for(var e=0,n=Array(t);e<t;e++)n[e]=r[e];return n}function f(r){var t=r.type,e=r.as,n=r.expr,s=r.with_offset;return["".concat(Object(i.toUpper)(t),"(").concat(n&&Object(o.a)(n)||"",")"),Object(i.commonOptionConnector)("AS","string"==typeof e?i.identifierToSql:o.a,e),Object(i.commonOptionConnector)(Object(i.toUpper)(s&&s.keyword),i.identifierToSql,s&&s.as)].filter(i.hasVal).join(" ")}function b(r){if(r)switch(r.type){case"pivot":case"unpivot":return function(r){var t=r.as,e=r.column,u=r.expr,a=r.in_expr,l=r.type,c=[Object(o.a)(u),"FOR",Object(s.f)(e),Object(n.a)(a)],f=["".concat(Object(i.toUpper)(l),"(").concat(c.join(" "),")")];return t&&f.push("AS",Object(i.identifierToSql)(t)),f.join(" ")}(r);default:return""}}function v(r){if(r){var t=r.keyword,e=r.expr,n=r.index,s=r.index_columns,u=r.parentheses,a=r.prefix,l=[];switch(t.toLowerCase()){case"forceseek":l.push(Object(i.toUpper)(t),"(".concat(Object(i.identifierToSql)(n)),"(".concat(s.map(o.a).filter(i.hasVal).join(", "),"))"));break;case"spatial_window_max_cells":l.push(Object(i.toUpper)(t),"=",Object(o.a)(e));break;case"index":l.push(Object(i.toUpper)(a),Object(i.toUpper)(t),u?"(".concat(e.map((function(r){return Object(i.identifierToSql)(r)})).join(", "),")"):"= ".concat(Object(i.identifierToSql)(e)));break;default:l.push(Object(o.a)(e))}return l.filter(i.hasVal).join(" ")}}function p(r,t){var e=r.name,n=r.symbol;return[Object(i.toUpper)(e),n,t].filter(i.hasVal).join(" ")}function L(r){var t=[];switch(r.keyword){case"as":t.push("AS","OF",Object(o.a)(r.of));break;case"from_to":t.push("FROM",Object(o.a)(r.from),"TO",Object(o.a)(r.to));break;case"between_and":t.push("BETWEEN",Object(o.a)(r.between),"AND",Object(o.a)(r.and));break;case"contained":t.push("CONTAINED","IN",Object(o.a)(r.in))}return t.filter(i.hasVal).join(" ")}function C(r){if("UNNEST"===Object(i.toUpper)(r.type))return f(r);var t,e,n,l,c=r.table,C=r.db,d=r.as,w=r.expr,y=r.operator,h=r.prefix,E=r.schema,A=r.server,m=r.suffix,T=r.tablesample,O=r.temporal_table,I=r.table_hint,R=r.surround,N=void 0===R?{}:R,g=Object(i.identifierToSql)(A,!1,N.server),S=Object(i.identifierToSql)(C,!1,N.db),_=Object(i.identifierToSql)(E,!1,N.schema),x=c&&Object(i.identifierToSql)(c,!1,N.table);if(w)switch(w.type){case"values":var U=w.parentheses,k=w.values,M=w.prefix,j=[U&&"(","",U&&")"],D=Object(u.c)(k);M&&(D=D.split("(").slice(1).map((function(r){return"".concat(Object(i.toUpper)(M),"(").concat(r)})).join("")),j[1]="VALUES ".concat(D),x=j.filter(i.hasVal).join("");break;case"tumble":x=function(r){if(!r)return"";var t=r.data,e=r.timecol,n=r.offset,o=r.size,u=[Object(i.identifierToSql)(t.expr.db),Object(i.identifierToSql)(t.expr.schema),Object(i.identifierToSql)(t.expr.table)].filter(i.hasVal).join("."),l="DESCRIPTOR(".concat(Object(s.f)(e.expr),")"),c=["TABLE(TUMBLE(TABLE ".concat(p(t,u)),p(e,l)],f=p(o,Object(a.a)(o.expr));return n&&n.expr?c.push(f,"".concat(p(n,Object(a.a)(n.expr)),"))")):c.push("".concat(f,"))")),c.filter(i.hasVal).join(", ")}(w);break;case"generator":e=(t=w).keyword,n=t.type,l=t.generators.map((function(r){return Object(i.commonTypeValue)(r).join(" ")})).join(", "),x="".concat(Object(i.toUpper)(e),"(").concat(Object(i.toUpper)(n),"(").concat(l,"))");break;default:x=Object(o.a)(w)}var P=[[g,S,_,x=[Object(i.toUpper)(h),x,Object(i.toUpper)(m)].filter(i.hasVal).join(" ")].filter(i.hasVal).join(".")];if(T){var G=["TABLESAMPLE",Object(o.a)(T.expr),Object(i.literalToSQL)(T.repeatable)].filter(i.hasVal).join(" ");P.push(G)}P.push(function(r){if(r){var t=r.keyword,e=r.expr;return[Object(i.toUpper)(t),L(e)].filter(i.hasVal).join(" ")}}(O),Object(i.commonOptionConnector)("AS","string"==typeof d?i.identifierToSql:o.a,d),b(y)),I&&P.push(Object(i.toUpper)(I.keyword),"(".concat(I.expr.map(v).filter(i.hasVal).join(", "),")"));var $=P.filter(i.hasVal).join(" ");return r.parentheses?"(".concat($,")"):$}function d(r){if(!r)return"";if(!Array.isArray(r)){var t=r.expr,e=r.parentheses,n=r.joins,s=d(t);if(e){for(var u=[],a=[],c=!0===e?1:e.length,f=0;f++<c;)u.push("("),a.push(")");var b=n&&n.length>0?d([""].concat(l(n))):"";return u.join("")+s+a.join("")+b}return s}var v=r[0],p=[];if("dual"===v.type)return"DUAL";p.push(C(v));for(var L=1;L<r.length;++L){var w=r[L],y=w.on,h=w.using,E=w.join,A=[],m=Array.isArray(w)||Object.hasOwnProperty.call(w,"joins");A.push(E?" ".concat(Object(i.toUpper)(E)):","),A.push(m?d(w):C(w)),A.push(Object(i.commonOptionConnector)("ON",o.a,y)),h&&A.push("USING (".concat(h.map(i.literalToSQL).join(", "),")")),p.push(A.filter(i.hasVal).join(" "))}return p.filter(i.hasVal).join("")}function w(r){var t=r.keyword,e=r.symbol,n=r.value,s=[t.toUpperCase()];e&&s.push(e);var u=Object(i.literalToSQL)(n);switch(t){case"partition by":case"default collate":u=Object(o.a)(n);break;case"options":u="(".concat(n.map((function(r){return[r.keyword,r.symbol,Object(o.a)(r.value)].join(" ")})).join(", "),")");break;case"cluster by":u=n.map(o.a).join(", ")}return s.push(u),s.filter(i.hasVal).join(" ")}},function(r,t,e){"use strict";e.d(t,"a",(function(){return p})),e.d(t,"b",(function(){return L})),e.d(t,"c",(function(){return T})),e.d(t,"d",(function(){return O})),e.d(t,"e",(function(){return C})),e.d(t,"f",(function(){return d})),e.d(t,"g",(function(){return w})),e.d(t,"h",(function(){return N})),e.d(t,"i",(function(){return R})),e.d(t,"j",(function(){return I})),e.d(t,"l",(function(){return y})),e.d(t,"m",(function(){return h})),e.d(t,"o",(function(){return E})),e.d(t,"n",(function(){return A})),e.d(t,"k",(function(){return m}));var n=e(2),s=e(15),o=e(0),u=e(1),a=e(3),i=e(18),l=e(5);function c(r,t){var e="undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(!e){if(Array.isArray(r)||(e=b(r))||t&&r&&"number"==typeof r.length){e&&(r=e);var n=0,s=function(){};return{s:s,n:function(){return n>=r.length?{done:!0}:{done:!1,value:r[n++]}},e:function(r){throw r},f:s}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,u=!0,a=!1;return{s:function(){e=e.call(r)},n:function(){var r=e.next();return u=r.done,r},e:function(r){a=!0,o=r},f:function(){try{u||null==e.return||e.return()}finally{if(a)throw o}}}}function f(r){return function(r){if(Array.isArray(r))return v(r)}(r)||function(r){if("undefined"!=typeof Symbol&&null!=r[Symbol.iterator]||null!=r["@@iterator"])return Array.from(r)}(r)||b(r)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function b(r,t){if(r){if("string"==typeof r)return v(r,t);var e={}.toString.call(r).slice(8,-1);return"Object"===e&&r.constructor&&(e=r.constructor.name),"Map"===e||"Set"===e?Array.from(r):"Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e)?v(r,t):void 0}}function v(r,t){(null==t||t>r.length)&&(t=r.length);for(var e=0,n=Array(t);e<t;e++)n[e]=r[e];return n}function p(r){var t=Object(u.a)(r.expr);return"".concat("CALL"," ").concat(t)}function L(r){var t=r.type,e=r.keyword,s=r.name,i=r.prefix,l=r.suffix,c=[Object(o.toUpper)(t),Object(o.toUpper)(e),Object(o.toUpper)(i)];switch(e){case"table":c.push(Object(a.c)(s));break;case"trigger":c.push([s[0].schema?"".concat(Object(o.identifierToSql)(s[0].schema),"."):"",Object(o.identifierToSql)(s[0].trigger)].filter(o.hasVal).join(""));break;case"database":case"schema":case"procedure":c.push(Object(o.identifierToSql)(s));break;case"view":c.push(Object(a.c)(s),r.options&&r.options.map(u.a).filter(o.hasVal).join(" "));break;case"index":c.push.apply(c,[Object(n.f)(s)].concat(f(r.table?["ON",Object(a.b)(r.table)]:[]),[r.options&&r.options.map(u.a).filter(o.hasVal).join(" ")]));break;case"type":c.push(s.map(n.f).join(", "),r.options&&r.options.map(u.a).filter(o.hasVal).join(" "))}return l&&c.push(l.map(u.a).filter(o.hasVal).join(" ")),c.filter(o.hasVal).join(" ")}function C(r){var t=r.type,e=r.table,n=Object(o.toUpper)(t),s="string"==typeof e?Object(o.identifierToSql)(e):Object(a.b)(e);return"".concat(n," ").concat(s)}function d(r){var t=r.type,e=r.name,n=r.args,s=[Object(o.toUpper)(t)],a=[e];return n&&a.push("(".concat(Object(u.a)(n).join(", "),")")),s.push(a.join("")),s.filter(o.hasVal).join(" ")}function w(r){var t=r.type,e=r.label,n=r.target,s=r.query,u=r.stmts;return[e,Object(o.toUpper)(t),n,"IN",Object(l.a)([s]),"LOOP",Object(l.a)(u),"END LOOP",e].filter(o.hasVal).join(" ")}function y(r){var t=r.type,e=r.level,n=r.raise,s=r.using,a=[Object(o.toUpper)(t),Object(o.toUpper)(e)];return n&&a.push([Object(o.literalToSQL)(n.keyword),"format"===n.type&&n.expr.length>0&&","].filter(o.hasVal).join(""),n.expr.map((function(r){return Object(u.a)(r)})).join(", ")),s&&a.push(Object(o.toUpper)(s.type),Object(o.toUpper)(s.option),s.symbol,s.expr.map((function(r){return Object(u.a)(r)})).join(", ")),a.filter(o.hasVal).join(" ")}function h(r){var t=r.type,e=r.table,n=[],s="".concat(t&&t.toUpperCase()," TABLE");if(e){var o,u=c(e);try{for(u.s();!(o=u.n()).done;){var i=o.value.map(a.b);n.push(i.join(" TO "))}}catch(r){u.e(r)}finally{u.f()}}return"".concat(s," ").concat(n.join(", "))}function E(r){var t=r.type,e=r.db,n=Object(o.toUpper)(t),s=Object(o.identifierToSql)(e);return"".concat(n," ").concat(s)}function A(r){var t=r.type,e=r.expr,n=r.keyword,s=Object(o.toUpper)(t),a=e.map(u.a).join(", ");return[s,Object(o.toUpper)(n),a].filter(o.hasVal).join(" ")}function m(r){var t=r.type,e=r.keyword,n=r.tables,s=[t.toUpperCase(),Object(o.toUpper)(e)];if("UNLOCK"===t.toUpperCase())return s.join(" ");var u,i=[],l=c(n);try{var b=function(){var r=u.value,t=r.table,e=r.lock_type,n=[Object(a.b)(t)];if(e){n.push(["prefix","type","suffix"].map((function(r){return Object(o.toUpper)(e[r])})).filter(o.hasVal).join(" "))}i.push(n.join(" "))};for(l.s();!(u=l.n()).done;)b()}catch(r){l.e(r)}finally{l.f()}return s.push.apply(s,[i.join(", ")].concat(f(function(r){var t=r.lock_mode,e=r.nowait,n=[];if(t){var s=t.mode;n.push(s.toUpperCase())}return e&&n.push(e.toUpperCase()),n}(r)))),s.filter(o.hasVal).join(" ")}function T(r){var t=r.type,e=r.keyword,n=r.expr;return[Object(o.toUpper)(t),Object(o.toUpper)(e),Object(u.a)(n)].filter(o.hasVal).join(" ")}function O(r){var t=r.type,e=r.declare,a=r.symbol,i=[Object(o.toUpper)(t)],l=e.map((function(r){var t=r.at,e=r.name,a=r.as,i=r.constant,l=r.datatype,c=r.not_null,f=r.prefix,b=r.definition,v=r.keyword,p=[[t,e].filter(o.hasVal).join(""),Object(o.toUpper)(a),Object(o.toUpper)(i)];switch(v){case"variable":p.push(Object(n.b)(l),Object(u.a)(r.collate),Object(o.toUpper)(c)),b&&p.push(Object(o.toUpper)(b.keyword),Object(u.a)(b.value));break;case"cursor":p.push(Object(o.toUpper)(f));break;case"table":p.push(Object(o.toUpper)(f),"(".concat(b.map(s.a).join(", "),")"))}return p.filter(o.hasVal).join(" ")})).join("".concat(a," "));return i.push(l),i.join(" ")}function I(r){var t=r.boolean_expr,e=r.else_expr,n=r.elseif_expr,s=r.if_expr,a=r.prefix,l=r.go,c=r.semicolons,f=r.suffix,b=r.type,v=[Object(o.toUpper)(b),Object(u.a)(t),Object(o.literalToSQL)(a),"".concat(Object(i.a)(s.ast||s)).concat(c[0]),Object(o.toUpper)(l)];return n&&v.push(n.map((function(r){return[Object(o.toUpper)(r.type),Object(u.a)(r.boolean_expr),"THEN",Object(i.a)(r.then.ast||r.then),r.semicolon].filter(o.hasVal).join(" ")})).join(" ")),e&&v.push("ELSE","".concat(Object(i.a)(e.ast||e)).concat(c[1])),v.push(Object(o.literalToSQL)(f)),v.filter(o.hasVal).join(" ")}function R(r){var t=r.name,e=r.host,n=[Object(o.literalToSQL)(t)];return e&&n.push("@",Object(o.literalToSQL)(e)),n.join("")}function N(r){var t=r.type,e=r.grant_option_for,s=r.keyword,a=r.objects,i=r.on,l=r.to_from,c=r.user_or_roles,f=r.with,b=[Object(o.toUpper)(t),Object(o.literalToSQL)(e)],v=a.map((function(r){var t=r.priv,e=r.columns,s=[Object(u.a)(t)];return e&&s.push("(".concat(e.map(n.f).join(", "),")")),s.join(" ")})).join(", ");if(b.push(v),i)switch(b.push("ON"),s){case"priv":b.push(Object(o.literalToSQL)(i.object_type),i.priv_level.map((function(r){return[Object(o.identifierToSql)(r.prefix),Object(o.identifierToSql)(r.name)].filter(o.hasVal).join(".")})).join(", "));break;case"proxy":b.push(R(i))}return b.push(Object(o.toUpper)(l),c.map(R).join(", ")),b.push(Object(o.literalToSQL)(f)),b.filter(o.hasVal).join(" ")}},function(r,t,e){"use strict";e.d(t,"b",(function(){return A})),e.d(t,"a",(function(){return m}));var n=e(11),s=e(1),o=e(3),u=e(0);var a=e(15),i=e(2);function l(r){var t=r.name,e=r.type;switch(e){case"table":case"view":var n=[Object(u.identifierToSql)(t.db),Object(u.identifierToSql)(t.table)].filter(u.hasVal).join(".");return"".concat(Object(u.toUpper)(e)," ").concat(n);case"column":return"COLUMN ".concat(Object(i.f)(t));default:return"".concat(Object(u.toUpper)(e)," ").concat(Object(u.literalToSQL)(t))}}function c(r){var t=r.keyword,e=r.expr;return[Object(u.toUpper)(t),Object(u.literalToSQL)(e)].filter(u.hasVal).join(" ")}var f=e(14);var b=e(9),v=e(17);var p=e(10),L=e(12),C=e(4);function d(r){var t=r.name,e=r.value;return["@".concat(t),"=",Object(s.a)(e)].filter(u.hasVal).join(" ")}var w=e(23),y=e(24);var h=e(25),E={alter:n.c,analyze:function(r){var t=r.type,e=r.table;return[Object(u.toUpper)(t),Object(o.b)(e)].join(" ")},attach:function(r){var t=r.type,e=r.database,n=r.expr,o=r.as,a=r.schema;return[Object(u.toUpper)(t),Object(u.toUpper)(e),Object(s.a)(n),Object(u.toUpper)(o),Object(u.identifierToSql)(a)].filter(u.hasVal).join(" ")},create:a.b,comment:function(r){var t=r.expr,e=r.keyword,n=r.target,s=r.type;return[Object(u.toUpper)(s),Object(u.toUpper)(e),l(n),c(t)].filter(u.hasVal).join(" ")},select:f.a,deallocate:C.c,delete:function(r){var t=r.columns,e=r.from,n=r.table,a=r.where,l=r.orderby,c=r.with,f=r.limit,p=r.returning,L=[Object(v.a)(c),"DELETE"],C=Object(i.i)(t,e);return L.push(C),Array.isArray(n)&&(1===n.length&&!0===n[0].addition||L.push(Object(o.c)(n))),L.push(Object(u.commonOptionConnector)("FROM",o.c,e)),L.push(Object(u.commonOptionConnector)("WHERE",s.a,a)),L.push(Object(s.c)(l,"order by")),L.push(Object(b.a)(f)),L.push(Object(u.returningToSQL)(p)),L.filter(u.hasVal).join(" ")},exec:function(r){var t=r.keyword,e=r.module,n=r.parameters;return[Object(u.toUpper)(t),Object(o.b)(e),(n||[]).map(d).filter(u.hasVal).join(", ")].filter(u.hasVal).join(" ")},execute:C.f,explain:function(r){var t=r.type,e=r.expr;return[Object(u.toUpper)(t),Object(f.a)(e)].join(" ")},for:C.g,update:p.b,if:C.j,insert:L.a,load_data:w.a,drop:C.b,truncate:C.b,replace:L.a,declare:C.d,use:C.o,rename:C.m,call:C.a,desc:C.e,describe:C.e,set:C.n,lock:C.k,unlock:C.k,show:h.a,grant:C.h,revoke:C.h,proc:function(r){var t=r.stmt;switch(t.type){case"assign":return Object(y.a)(t);case"return":return function(r){var t=r.type,e=r.expr;return[Object(u.toUpper)(t),Object(s.a)(e)].join(" ")}(t)}},raise:C.l,transaction:function(r){var t=r.expr,e=t.action,n=t.keyword,s=t.modes,o=[Object(u.literalToSQL)(e),Object(u.toUpper)(n)];return s&&o.push(s.map(u.literalToSQL).join(", ")),o.filter(u.hasVal).join(" ")}};function A(r){if(!r)return"";for(var t=E[r.type],e=r,n=e._parentheses,o=e._orderby,a=e._limit,i=[n&&"(",t(r)];r._next;){var l=E[r._next.type],c=Object(u.toUpper)(r.set_op);i.push(c,l(r._next)),r=r._next}return i.push(n&&")",Object(s.c)(o,"order by"),Object(b.a)(a)),i.filter(u.hasVal).join(" ")}function m(r){for(var t=[],e=0,n=r.length;e<n;++e){var s=r[e]&&r[e].ast?r[e].ast:r[e],o=A(s);e===n-1&&"transaction"===s.type&&(o="".concat(o," ;")),t.push(o)}return t.join(" ; ")}},function(r,t,e){"use strict";e.d(t,"a",(function(){return i})),e.d(t,"b",(function(){return l})),e.d(t,"c",(function(){return c})),e.d(t,"d",(function(){return f})),e.d(t,"e",(function(){return v})),e.d(t,"f",(function(){return p})),e.d(t,"g",(function(){return L})),e.d(t,"h",(function(){return b})),e.d(t,"i",(function(){return d})),e.d(t,"j",(function(){return C}));var n=e(2),s=e(8),o=e(1),u=e(0),a=e(16);function i(r){var t=r.args,e=r.type,n=r.over,s=t.expr,i=t.having,l="".concat(Object(u.toUpper)(e),"(").concat(Object(o.a)(s));return i&&(l="".concat(l," HAVING ").concat(Object(u.toUpper)(i.prefix)," ").concat(Object(o.a)(i.expr))),[l="".concat(l,")"),Object(a.a)(n)].filter(u.hasVal).join(" ")}function l(r){if(!r||!r.array)return"";var t=r.array.keyword;if(t)return Object(u.toUpper)(t);for(var e=r.array,n=e.dimension,s=e.length,o=[],a=0;a<n;a++)o.push("["),s&&s[a]&&o.push(Object(u.literalToSQL)(s[a])),o.push("]");return o.join("")}function c(r){for(var t=r.target,e=r.expr,a=r.keyword,i=r.symbol,c=r.as,f=r.offset,b=r.parentheses,v=r.collate,p=Object(n.d)({expr:e,offset:f}),L=[],C=0,d=t.length;C<d;++C){var w=t[C],y=w.angle_brackets,h=w.length,E=w.dataType,A=w.parentheses,m=w.quoted,T=w.scale,O=w.suffix,I=w.expr,R=I?Object(o.a)(I):"";null!=h&&(R=T?"".concat(h,", ").concat(T):h),A&&(R="(".concat(R,")")),y&&(R="<".concat(R,">")),O&&O.length&&(R+=" ".concat(O.map(u.literalToSQL).join(" ")));var N="::",g="",S=[];"as"===i&&(0===C&&(p="".concat(Object(u.toUpper)(a),"(").concat(p)),g=")",N=" ".concat(i.toUpperCase()," ")),0===C&&S.push(p);var _=l(w);S.push(N,m,E,m,_,R,g),L.push(S.filter(u.hasVal).join(""))}var x=Object(s.a)(v);c&&L.push(" AS ".concat(Object(u.identifierToSql)(c)));var U=[L.filter(u.hasVal).join(""),x].filter(u.hasVal).join(" ");return b?"(".concat(U,")"):U}function f(r){var t=r.args,e=r.type,n=t.field,s=t.cast_type,a=t.source,i=["".concat(Object(u.toUpper)(e),"(").concat(Object(u.toUpper)(n)),"FROM",Object(u.toUpper)(s),Object(o.a)(a)];return"".concat(i.filter(u.hasVal).join(" "),")")}function b(r){var t=r.expr,e=t.key,n=t.value,s=t.on,a=[Object(o.a)(e),"VALUE",Object(o.a)(n)];return s&&a.push("ON","NULL",Object(o.a)(s)),a.filter(u.hasVal).join(" ")}function v(r){var t=r.args,e=r.type,n=["input","path","outer","recursive","mode"].map((function(r){return function(r){if(!r)return"";var t=r.type,e=r.symbol,n=r.value;return[Object(u.toUpper)(t),e,Object(o.a)(n)].filter(u.hasVal).join(" ")}(t[r])})).filter(u.hasVal).join(", ");return"".concat(Object(u.toUpper)(e),"(").concat(n,")")}function p(r){var t=r.value,e=t.name,n=t.symbol,s=t.expr;return[e,n,Object(o.a)(s)].filter(u.hasVal).join(" ")}function L(r){var t=r.args,e=r.array_index,i=r.collate,l=r.name,c=r.args_parentheses,f=r.parentheses,b=r.within_group,v=r.over,p=r.suffix,L=Object(a.a)(v),C=function(r){if(!r)return"";var t=r.type,e=r.keyword,n=r.orderby;return[Object(u.toUpper)(t),Object(u.toUpper)(e),"(".concat(Object(o.c)(n,"order by"),")")].filter(u.hasVal).join(" ")}(b),d=Object(o.a)(p),w=Object(s.a)(i),y=[Object(u.literalToSQL)(l.schema),l.name.map(u.literalToSQL).join(".")].filter(u.hasVal).join(".");if(!t)return[y,w,C,L].filter(u.hasVal).join(" ");var h=r.separator||", ",E=0;if("TRIM"===Object(u.toUpper)(y))for(var A=0,m=t.value.length;A<m;++A){var T=t.value[A];if("origin"===T.type&&"from"===T.value){E=A;break}}var O=[y];O.push(!1===c?" ":"(");var I=Object(o.a)(t);if(Array.isArray(h)){for(var R=I[0],N=1,g=I.length;N<g;++N)R=[R,I[N]].join(" ".concat(Object(o.a)(h[N-1])," "));O.push(R)}else"TRIM"===Object(u.toUpper)(y)&&E>0?O.push([I.slice(0,E+1).join(" "),I.slice(E+1).join(", ")].join(" ")):O.push(I.join(h));return!1!==c&&O.push(")"),O.push(Object(n.a)(e)),O=[O.join(""),d,w].filter(u.hasVal).join(" "),[f?"(".concat(O,")"):O,C,L].filter(u.hasVal).join(" ")}function C(r){var t=r.as,e=r.name,n=r.args,s=[Object(u.literalToSQL)(e.schema),e.name.map(u.literalToSQL).join(".")].filter(u.hasVal).join(".");return["".concat(s,"(").concat(Object(o.a)(n).join(", "),")"),"AS",L(t)].join(" ")}function d(r){var t=r.args,e=r.expr,n=t.value,s=t.parentheses,u=n.map(o.a).join(", ");return[s?"(".concat(u,")"):u,"->",Object(o.a)(e)].join(" ")}},function(r,t,e){(function(r){var n,s=function(r){"use strict";var t=1e7,e=9007199254740992,n=f(e),o="function"==typeof BigInt;function u(r,t,e,n){return void 0===r?u[0]:void 0!==t&&(10!=+t||e)?$(r,t,e,n):V(r)}function a(r,t){this.value=r,this.sign=t,this.isSmall=!1}function i(r){this.value=r,this.sign=r<0,this.isSmall=!0}function l(r){this.value=r}function c(r){return-e<r&&r<e}function f(r){return r<1e7?[r]:r<1e14?[r%1e7,Math.floor(r/1e7)]:[r%1e7,Math.floor(r/1e7)%1e7,Math.floor(r/1e14)]}function b(r){v(r);var e=r.length;if(e<4&&N(r,n)<0)switch(e){case 0:return 0;case 1:return r[0];case 2:return r[0]+r[1]*t;default:return r[0]+(r[1]+r[2]*t)*t}return r}function v(r){for(var t=r.length;0===r[--t];);r.length=t+1}function p(r){for(var t=new Array(r),e=-1;++e<r;)t[e]=0;return t}function L(r){return r>0?Math.floor(r):Math.ceil(r)}function C(r,e){var n,s,o=r.length,u=e.length,a=new Array(o),i=0,l=t;for(s=0;s<u;s++)i=(n=r[s]+e[s]+i)>=l?1:0,a[s]=n-i*l;for(;s<o;)i=(n=r[s]+i)===l?1:0,a[s++]=n-i*l;return i>0&&a.push(i),a}function d(r,t){return r.length>=t.length?C(r,t):C(t,r)}function w(r,e){var n,s,o=r.length,u=new Array(o),a=t;for(s=0;s<o;s++)n=r[s]-a+e,e=Math.floor(n/a),u[s]=n-e*a,e+=1;for(;e>0;)u[s++]=e%a,e=Math.floor(e/a);return u}function y(r,t){var e,n,s=r.length,o=t.length,u=new Array(s),a=0;for(e=0;e<o;e++)(n=r[e]-a-t[e])<0?(n+=1e7,a=1):a=0,u[e]=n;for(e=o;e<s;e++){if(!((n=r[e]-a)<0)){u[e++]=n;break}n+=1e7,u[e]=n}for(;e<s;e++)u[e]=r[e];return v(u),u}function h(r,t,e){var n,s,o=r.length,u=new Array(o),l=-t;for(n=0;n<o;n++)s=r[n]+l,l=Math.floor(s/1e7),s%=1e7,u[n]=s<0?s+1e7:s;return"number"==typeof(u=b(u))?(e&&(u=-u),new i(u)):new a(u,e)}function E(r,t){var e,n,s,o,u=r.length,a=t.length,i=p(u+a);for(s=0;s<u;++s){o=r[s];for(var l=0;l<a;++l)e=o*t[l]+i[s+l],n=Math.floor(e/1e7),i[s+l]=e-1e7*n,i[s+l+1]+=n}return v(i),i}function A(r,e){var n,s,o=r.length,u=new Array(o),a=t,i=0;for(s=0;s<o;s++)n=r[s]*e+i,i=Math.floor(n/a),u[s]=n-i*a;for(;i>0;)u[s++]=i%a,i=Math.floor(i/a);return u}function m(r,t){for(var e=[];t-- >0;)e.push(0);return e.concat(r)}function T(r,e,n){return new a(r<t?A(e,r):E(e,f(r)),n)}function O(r){var t,e,n,s,o=r.length,u=p(o+o);for(n=0;n<o;n++){e=0-(s=r[n])*s;for(var a=n;a<o;a++)t=s*r[a]*2+u[n+a]+e,e=Math.floor(t/1e7),u[n+a]=t-1e7*e;u[n+o]=e}return v(u),u}function I(r,t){var e,n,s,o,u=r.length,a=p(u);for(s=0,e=u-1;e>=0;--e)s=(o=1e7*s+r[e])-(n=L(o/t))*t,a[e]=0|n;return[a,0|s]}function R(r,e){var n,s=V(e);if(o)return[new l(r.value/s.value),new l(r.value%s.value)];var c,C=r.value,d=s.value;if(0===d)throw new Error("Cannot divide by zero");if(r.isSmall)return s.isSmall?[new i(L(C/d)),new i(C%d)]:[u[0],r];if(s.isSmall){if(1===d)return[r,u[0]];if(-1==d)return[r.negate(),u[0]];var w=Math.abs(d);if(w<t){c=b((n=I(C,w))[0]);var h=n[1];return r.sign&&(h=-h),"number"==typeof c?(r.sign!==s.sign&&(c=-c),[new i(c),new i(h)]):[new a(c,r.sign!==s.sign),new i(h)]}d=f(w)}var E=N(C,d);if(-1===E)return[u[0],r];if(0===E)return[u[r.sign===s.sign?1:-1],u[0]];c=(n=C.length+d.length<=200?function(r,e){var n,s,o,u,a,i,l,c=r.length,f=e.length,v=t,L=p(e.length),C=e[f-1],d=Math.ceil(v/(2*C)),w=A(r,d),y=A(e,d);for(w.length<=c&&w.push(0),y.push(0),C=y[f-1],s=c-f;s>=0;s--){for(n=v-1,w[s+f]!==C&&(n=Math.floor((w[s+f]*v+w[s+f-1])/C)),o=0,u=0,i=y.length,a=0;a<i;a++)o+=n*y[a],l=Math.floor(o/v),u+=w[s+a]-(o-l*v),o=l,u<0?(w[s+a]=u+v,u=-1):(w[s+a]=u,u=0);for(;0!==u;){for(n-=1,o=0,a=0;a<i;a++)(o+=w[s+a]-v+y[a])<0?(w[s+a]=o+v,o=0):(w[s+a]=o,o=1);u+=o}L[s]=n}return w=I(w,d)[0],[b(L),b(w)]}(C,d):function(r,t){for(var e,n,s,o,u,a=r.length,i=t.length,l=[],c=[];a;)if(c.unshift(r[--a]),v(c),N(c,t)<0)l.push(0);else{s=1e7*c[(n=c.length)-1]+c[n-2],o=1e7*t[i-1]+t[i-2],n>i&&(s=1e7*(s+1)),e=Math.ceil(s/o);do{if(N(u=A(t,e),c)<=0)break;e--}while(e);l.push(e),c=y(c,u)}return l.reverse(),[b(l),b(c)]}(C,d))[0];var m=r.sign!==s.sign,T=n[1],O=r.sign;return"number"==typeof c?(m&&(c=-c),c=new i(c)):c=new a(c,m),"number"==typeof T?(O&&(T=-T),T=new i(T)):T=new a(T,O),[c,T]}function N(r,t){if(r.length!==t.length)return r.length>t.length?1:-1;for(var e=r.length-1;e>=0;e--)if(r[e]!==t[e])return r[e]>t[e]?1:-1;return 0}function g(r){var t=r.abs();return!t.isUnit()&&(!!(t.equals(2)||t.equals(3)||t.equals(5))||!(t.isEven()||t.isDivisibleBy(3)||t.isDivisibleBy(5))&&(!!t.lesser(49)||void 0))}function S(r,t){for(var e,n,o,u=r.prev(),a=u,i=0;a.isEven();)a=a.divide(2),i++;r:for(n=0;n<t.length;n++)if(!r.lesser(t[n])&&!(o=s(t[n]).modPow(a,r)).isUnit()&&!o.equals(u)){for(e=i-1;0!=e;e--){if((o=o.square().mod(r)).isUnit())return!1;if(o.equals(u))continue r}return!1}return!0}a.prototype=Object.create(u.prototype),i.prototype=Object.create(u.prototype),l.prototype=Object.create(u.prototype),a.prototype.add=function(r){var t=V(r);if(this.sign!==t.sign)return this.subtract(t.negate());var e=this.value,n=t.value;return t.isSmall?new a(w(e,Math.abs(n)),this.sign):new a(d(e,n),this.sign)},a.prototype.plus=a.prototype.add,i.prototype.add=function(r){var t=V(r),e=this.value;if(e<0!==t.sign)return this.subtract(t.negate());var n=t.value;if(t.isSmall){if(c(e+n))return new i(e+n);n=f(Math.abs(n))}return new a(w(n,Math.abs(e)),e<0)},i.prototype.plus=i.prototype.add,l.prototype.add=function(r){return new l(this.value+V(r).value)},l.prototype.plus=l.prototype.add,a.prototype.subtract=function(r){var t=V(r);if(this.sign!==t.sign)return this.add(t.negate());var e=this.value,n=t.value;return t.isSmall?h(e,Math.abs(n),this.sign):function(r,t,e){var n;return N(r,t)>=0?n=y(r,t):(n=y(t,r),e=!e),"number"==typeof(n=b(n))?(e&&(n=-n),new i(n)):new a(n,e)}(e,n,this.sign)},a.prototype.minus=a.prototype.subtract,i.prototype.subtract=function(r){var t=V(r),e=this.value;if(e<0!==t.sign)return this.add(t.negate());var n=t.value;return t.isSmall?new i(e-n):h(n,Math.abs(e),e>=0)},i.prototype.minus=i.prototype.subtract,l.prototype.subtract=function(r){return new l(this.value-V(r).value)},l.prototype.minus=l.prototype.subtract,a.prototype.negate=function(){return new a(this.value,!this.sign)},i.prototype.negate=function(){var r=this.sign,t=new i(-this.value);return t.sign=!r,t},l.prototype.negate=function(){return new l(-this.value)},a.prototype.abs=function(){return new a(this.value,!1)},i.prototype.abs=function(){return new i(Math.abs(this.value))},l.prototype.abs=function(){return new l(this.value>=0?this.value:-this.value)},a.prototype.multiply=function(r){var e,n,s,o=V(r),i=this.value,l=o.value,c=this.sign!==o.sign;if(o.isSmall){if(0===l)return u[0];if(1===l)return this;if(-1===l)return this.negate();if((e=Math.abs(l))<t)return new a(A(i,e),c);l=f(e)}return n=i.length,s=l.length,new a(-.012*n-.012*s+15e-6*n*s>0?function r(t,e){var n=Math.max(t.length,e.length);if(n<=30)return E(t,e);n=Math.ceil(n/2);var s=t.slice(n),o=t.slice(0,n),u=e.slice(n),a=e.slice(0,n),i=r(o,a),l=r(s,u),c=r(d(o,s),d(a,u)),f=d(d(i,m(y(y(c,i),l),n)),m(l,2*n));return v(f),f}(i,l):E(i,l),c)},a.prototype.times=a.prototype.multiply,i.prototype._multiplyBySmall=function(r){return c(r.value*this.value)?new i(r.value*this.value):T(Math.abs(r.value),f(Math.abs(this.value)),this.sign!==r.sign)},a.prototype._multiplyBySmall=function(r){return 0===r.value?u[0]:1===r.value?this:-1===r.value?this.negate():T(Math.abs(r.value),this.value,this.sign!==r.sign)},i.prototype.multiply=function(r){return V(r)._multiplyBySmall(this)},i.prototype.times=i.prototype.multiply,l.prototype.multiply=function(r){return new l(this.value*V(r).value)},l.prototype.times=l.prototype.multiply,a.prototype.square=function(){return new a(O(this.value),!1)},i.prototype.square=function(){var r=this.value*this.value;return c(r)?new i(r):new a(O(f(Math.abs(this.value))),!1)},l.prototype.square=function(r){return new l(this.value*this.value)},a.prototype.divmod=function(r){var t=R(this,r);return{quotient:t[0],remainder:t[1]}},l.prototype.divmod=i.prototype.divmod=a.prototype.divmod,a.prototype.divide=function(r){return R(this,r)[0]},l.prototype.over=l.prototype.divide=function(r){return new l(this.value/V(r).value)},i.prototype.over=i.prototype.divide=a.prototype.over=a.prototype.divide,a.prototype.mod=function(r){return R(this,r)[1]},l.prototype.mod=l.prototype.remainder=function(r){return new l(this.value%V(r).value)},i.prototype.remainder=i.prototype.mod=a.prototype.remainder=a.prototype.mod,a.prototype.pow=function(r){var t,e,n,s=V(r),o=this.value,a=s.value;if(0===a)return u[1];if(0===o)return u[0];if(1===o)return u[1];if(-1===o)return s.isEven()?u[1]:u[-1];if(s.sign)return u[0];if(!s.isSmall)throw new Error("The exponent "+s.toString()+" is too large.");if(this.isSmall&&c(t=Math.pow(o,a)))return new i(L(t));for(e=this,n=u[1];!0&a&&(n=n.times(e),--a),0!==a;)a/=2,e=e.square();return n},i.prototype.pow=a.prototype.pow,l.prototype.pow=function(r){var t=V(r),e=this.value,n=t.value,s=BigInt(0),o=BigInt(1),a=BigInt(2);if(n===s)return u[1];if(e===s)return u[0];if(e===o)return u[1];if(e===BigInt(-1))return t.isEven()?u[1]:u[-1];if(t.isNegative())return new l(s);for(var i=this,c=u[1];(n&o)===o&&(c=c.times(i),--n),n!==s;)n/=a,i=i.square();return c},a.prototype.modPow=function(r,t){if(r=V(r),(t=V(t)).isZero())throw new Error("C