Permalink
Browse files

updated squel.js

  • Loading branch information...
1 parent e61d959 commit 2712581fd0feddf3f94179412dfc43421f1be9e3 @hiddentao committed Aug 27, 2016
Showing with 2 additions and 2 deletions.
  1. +2 −2 public/js/squel.min.js
View
4 public/js/squel.min.js
@@ -1,2 +1,2 @@
-/*! squel | https://github.com/hiddentao/squel | BSD license */!function(t,e){"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?module.exports=e():t.squel=e()}(this,function(){"use strict";function t(t){if(Array.isArray(t)){for(var e=0,n=Array(t.length);e<t.length;e++)n[e]=t[e];return n}return Array.from(t)}function e(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function n(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}function r(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function i(t,e){return t.length?t+e:t}function o(t){for(var e=arguments.length,n=Array(e>1?e-1:0),r=1;e>r;r++)n[r-1]=arguments[r];if(t&&n){var i=!0,o=!1,a=void 0;try{for(var l,u=function(){var e=l.value;"object"===("undefined"==typeof e?"undefined":y(e))&&Object.getOwnPropertyNames(e).forEach(function(n){t[n]=e[n]})},s=n[Symbol.iterator]();!(i=(l=s.next()).done);i=!0)u()}catch(c){o=!0,a=c}finally{try{!i&&s["return"]&&s["return"]()}finally{if(o)throw a}}}return t}function a(t){return t&&t.constructor.prototype===Object.prototype}function l(t){return t&&t.constructor.prototype===Array.prototype}function u(t){if(t&&t.constructor&&t.constructor.toString){var e=t.constructor.toString().match(/function\s*(\w+)/);if(e&&2===e.length)return e[1]}}function s(t){if(!t)return t;if("function"==typeof t.clone)return t.clone();if(!a(t)&&!l(t))return JSON.parse(JSON.stringify(t));var e=function(){var e=new t.constructor;return Object.getOwnPropertyNames(t).forEach(function(n){"function"!=typeof t[n]&&(e[n]=s(t[n]))}),{v:e}}();return"object"===("undefined"==typeof e?"undefined":y(e))?e.v:void 0}function c(t,e,n){var r="undefined"==typeof e?"undefined":y(e);if("function"!==r&&"string"!==r)throw new Error("type must be a class constructor or string");if("function"!=typeof n)throw new Error("handler must be a function");var i=!0,o=!1,a=void 0;try{for(var l,u=t[Symbol.iterator]();!(i=(l=u.next()).done);i=!0){var s=l.value;if(s.type===e)return void(s.handler=n)}}catch(c){o=!0,a=c}finally{try{!i&&u["return"]&&u["return"]()}finally{if(o)throw a}}t.push({type:e,handler:n})}function f(t){for(var e=arguments.length,n=Array(e>1?e-1:0),r=1;e>r;r++)n[r-1]=arguments[r];var i=!0,o=!1,a=void 0;try{for(var l,u=n[Symbol.iterator]();!(i=(l=u.next()).done);i=!0){var s=l.value,c=!0,f=!1,h=void 0;try{for(var v,d=s[Symbol.iterator]();!(c=(v=d.next()).done);c=!0){var p=v.value;if(("undefined"==typeof t?"undefined":y(t))===p.type||"string"!=typeof p.type&&t instanceof p.type)return p.handler}}catch(g){f=!0,h=g}finally{try{!c&&d["return"]&&d["return"]()}finally{if(f)throw h}}}}catch(g){o=!0,a=g}finally{try{!i&&u["return"]&&u["return"]()}finally{if(o)throw a}}}function h(){var h=arguments.length<=0||void 0===arguments[0]?null:arguments[0],p={_getObjectClassName:u};p.DefaultQueryBuilderOptions={autoQuoteTableNames:!1,autoQuoteFieldNames:!1,autoQuoteAliasNames:!0,useAsForTableAliasNames:!1,nameQuoteCharacter:"`",tableAliasQuoteCharacter:"`",fieldAliasQuoteCharacter:'"',valueHandlers:[],parameterCharacter:"?",numberedParameters:!1,numberedParametersPrefix:"$",numberedParametersStartAt:1,replaceSingleQuotes:!1,singleQuoteReplacement:"''",separator:" ",stringFormatter:null},p.globalValueHandlers=[],p.registerValueHandler=function(t,e){c(p.globalValueHandlers,t,e)},p.Cloneable=function(){function t(){r(this,t)}return d(t,[{key:"clone",value:function(){var t=new this.constructor;return o(t,s(o({},this)))}}]),t}(),p.BaseBuilder=function(i){function a(t){r(this,a);var n=e(this,Object.getPrototypeOf(a).call(this)),i=JSON.parse(JSON.stringify(p.DefaultQueryBuilderOptions));return n.options=o({},i,t),n}return n(a,i),d(a,[{key:"registerValueHandler",value:function(t,e){return c(this.options.valueHandlers,t,e),this}},{key:"_sanitizeExpression",value:function(t){if(!(t instanceof p.BaseBuilder)&&"string"!=typeof t)throw new Error("expression must be a string or builder instance");return t}},{key:"_sanitizeName",value:function(t,e){if("string"!=typeof t)throw new Error(e+" must be a string");return t}},{key:"_sanitizeField",value:function(t){return t instanceof p.BaseBuilder||(t=this._sanitizeName(t,"field name")),t}},{key:"_sanitizeBaseBuilder",value:function(t){if(t instanceof p.BaseBuilder)return t;throw new Error("must be a builder instance")}},{key:"_sanitizeTable",value:function(t){if("string"!=typeof t)try{t=this._sanitizeBaseBuilder(t)}catch(e){throw new Error("table name must be a string or a builder")}else t=this._sanitizeName(t,"table");return t}},{key:"_sanitizeTableAlias",value:function(t){return this._sanitizeName(t,"table alias")}},{key:"_sanitizeFieldAlias",value:function(t){return this._sanitizeName(t,"field alias")}},{key:"_sanitizeLimitOffset",value:function(t){if(t=parseInt(t),0>t||isNaN(t))throw new Error("limit/offset must be >= 0");return t}},{key:"_sanitizeValue",value:function(t){var e="undefined"==typeof t?"undefined":y(t);if(null===t);else if("string"===e||"number"===e||"boolean"===e);else if(t instanceof p.BaseBuilder);else{var n=!!f(t,this.options.valueHandlers,p.globalValueHandlers);if(!n)throw new Error("field value must be a string, number, boolean, null or one of the registered custom value types")}return t}},{key:"_escapeValue",value:function(t){return this.options.replaceSingleQuotes?t.replace(/\'/g,this.options.singleQuoteReplacement):t}},{key:"_formatTableName",value:function(t){if(this.options.autoQuoteTableNames){var e=this.options.nameQuoteCharacter;t=""+e+t+e}return t}},{key:"_formatFieldAlias",value:function(t){if(this.options.autoQuoteAliasNames){var e=this.options.fieldAliasQuoteCharacter;t=""+e+t+e}return t}},{key:"_formatTableAlias",value:function(t){if(this.options.autoQuoteAliasNames){var e=this.options.tableAliasQuoteCharacter;t=""+e+t+e}return this.options.useAsForTableAliasNames?"AS "+t:t}},{key:"_formatFieldName",value:function(t){var e=this,n=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];return this.options.autoQuoteFieldNames&&!function(){var r=e.options.nameQuoteCharacter;t=n.ignorePeriodsForFieldNameQuotes?""+r+t+r:t.split(".").map(function(t){return"*"===t?t:""+r+t+r}).join(".")}(),t}},{key:"_formatCustomValue",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?!1:arguments[1],n=f(t,this.options.valueHandlers,p.globalValueHandlers);return n&&(t=n(t,e)),{formatted:!!n,value:t}}},{key:"_formatValueForParamArray",value:function(t){var e=this;return l(t)?t.map(function(t){return e._formatValueForParamArray(t)}):this._formatCustomValue(t,!0).value}},{key:"_formatValueForQueryString",value:function(t){var e=this,n=arguments.length<=1||void 0===arguments[1]?{}:arguments[1],r=this._formatCustomValue(t),i=r.formatted,o=r.value;if(i)return this._applyNestingFormatting(o);if(l(o))o=o.map(function(t){return e._formatValueForQueryString(t)}),o=this._applyNestingFormatting(o.join(", "));else{var a="undefined"==typeof o?"undefined":y(o);if(null===o)o="NULL";else if("boolean"===a)o=o?"TRUE":"FALSE";else if(o instanceof p.BaseBuilder)o=this._applyNestingFormatting(o.toString());else if("number"!==a){if("string"===a&&this.options.stringFormatter)return this.options.stringFormatter(o);if(n.dontQuote)o=""+o;else{var u=this._escapeValue(o);o="'"+u+"'"}}}return o}},{key:"_applyNestingFormatting",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?!0:arguments[1];return t&&"string"==typeof t&&e&&("("!==t.charAt(0)||")"!==t.charAt(t.length-1))?"("+t+")":t}},{key:"_buildString",value:function(e,n){var r=arguments.length<=2||void 0===arguments[2]?{}:arguments[2],i=r.nested,o=r.buildParameterized,a=r.formattingOptions;n=n||[],e=e||"";for(var u="",s=-1,c=[],f=this.options.parameterCharacter,h=0;e.length>h;)if(e.substr(h,f.length)===f){var v=n[++s];if(o)if(v instanceof p.BaseBuilder){var d=v._toParamString({buildParameterized:o,nested:!0});u+=d.text,c.push.apply(c,t(d.values))}else if(v=this._formatValueForParamArray(v),l(v)){var y=v.map(function(){return f}).join(", ");u+="("+y+")",c.push.apply(c,t(v))}else u+=f,c.push(v);else u+=this._formatValueForQueryString(v,a);h+=f.length}else u+=e.charAt(h),h++;return{text:this._applyNestingFormatting(u,!!i),values:c}}},{key:"_buildManyStrings",value:function(e,n){for(var r=arguments.length<=2||void 0===arguments[2]?{}:arguments[2],i=[],o=[],a=0;e.length>a;++a){var l=e[a],u=n[a],s=this._buildString(l,u,{buildParameterized:r.buildParameterized,nested:!1}),c=s.text,f=s.values;i.push(c),o.push.apply(o,t(f))}return i=i.join(this.options.separator),{text:i.length?this._applyNestingFormatting(i,!!r.nested):"",values:o}}},{key:"_toParamString",value:function(t){throw new Error("Not yet implemented")}},{key:"toString",value:function(){var t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];return this._toParamString(t).text}},{key:"toParam",value:function(){var t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];return this._toParamString(o({},t,{buildParameterized:!0}))}}]),a}(p.Cloneable),p.Expression=function(i){function o(t){r(this,o);var n=e(this,Object.getPrototypeOf(o).call(this,t));return n._nodes=[],n}return n(o,i),d(o,[{key:"and",value:function(t){for(var e=arguments.length,n=Array(e>1?e-1:0),r=1;e>r;r++)n[r-1]=arguments[r];return t=this._sanitizeExpression(t),this._nodes.push({type:"AND",expr:t,para:n}),this}},{key:"or",value:function(t){for(var e=arguments.length,n=Array(e>1?e-1:0),r=1;e>r;r++)n[r-1]=arguments[r];return t=this._sanitizeExpression(t),this._nodes.push({type:"OR",expr:t,para:n}),this}},{key:"_toParamString",value:function(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],n=[],r=[],i=!0,o=!1,a=void 0;try{for(var l,u=this._nodes[Symbol.iterator]();!(i=(l=u.next()).done);i=!0){var s=l.value,c=s.type,f=s.expr,h=s.para,v=f instanceof p.Expression?f._toParamString({buildParameterized:e.buildParameterized,nested:!0}):this._buildString(f,h,{buildParameterized:e.buildParameterized}),d=v.text,y=v.values;n.length&&n.push(c),n.push(d),r.push.apply(r,t(y))}}catch(g){o=!0,a=g}finally{try{!i&&u["return"]&&u["return"]()}finally{if(o)throw a}}return n=n.join(" "),{text:this._applyNestingFormatting(n,!!e.nested),values:r}}}]),o}(p.BaseBuilder),p.Case=function(l){function u(t){var n=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];r(this,u);var i=e(this,Object.getPrototypeOf(u).call(this,n));return a(t)&&(n=t,t=null),t&&(i._fieldName=i._sanitizeField(t)),i.options=o({},p.DefaultQueryBuilderOptions,n),i._cases=[],i._elseValue=null,i}return n(u,l),d(u,[{key:"when",value:function(t){for(var e=arguments.length,n=Array(e>1?e-1:0),r=1;e>r;r++)n[r-1]=arguments[r];return this._cases.unshift({expression:t,values:n}),this}},{key:"then",value:function(t){if(0==this._cases.length)throw new Error("when() needs to be called first");return this._cases[0].result=t,this}},{key:"else",value:function(t){return this._elseValue=t,this}},{key:"_toParamString",value:function(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],n="",r=[],o=!0,a=!1,l=void 0;try{for(var u,s=this._cases[Symbol.iterator]();!(o=(u=s.next()).done);o=!0){var c=u.value,f=c.expression,h=c.values,v=c.result;n=i(n," ");var d=this._buildString(f,h,{buildParameterized:e.buildParameterized,nested:!0});n+="WHEN "+d.text+" THEN "+this._formatValueForQueryString(v),r.push.apply(r,t(d.values))}}catch(y){a=!0,l=y}finally{try{!o&&s["return"]&&s["return"]()}finally{if(a)throw l}}return n.length?(n+=" ELSE "+this._formatValueForQueryString(this._elseValue)+" END",this._fieldName&&(n=this._fieldName+" "+n),n="CASE "+n):n=this._formatValueForQueryString(this._elseValue),{text:n,values:r}}}]),u}(p.BaseBuilder),p.Block=function(t){function i(t){return r(this,i),e(this,Object.getPrototypeOf(i).call(this,t))}return n(i,t),d(i,[{key:"exposedMethods",value:function(){for(var t={},e=this;e;)Object.getOwnPropertyNames(e).forEach(function(n){"constructor"===n||"function"!=typeof e[n]||"_"===n.charAt(0)||p.Block.prototype[n]||(t[n]=e[n])}),e=Object.getPrototypeOf(e);return t}}]),i}(p.BaseBuilder),p.StringBlock=function(t){function i(t,n){r(this,i);var o=e(this,Object.getPrototypeOf(i).call(this,t));return o._str=n,o}return n(i,t),d(i,[{key:"_toParamString",value:function(){arguments.length<=0||void 0===arguments[0]?{}:arguments[0];return{text:this._str,values:[]}}}]),i}(p.Block),p.FunctionBlock=function(t){function i(t){r(this,i);var n=e(this,Object.getPrototypeOf(i).call(this,t));return n._strings=[],n._values=[],n}return n(i,t),d(i,[{key:"function",value:function(t){this._strings.push(t);for(var e=arguments.length,n=Array(e>1?e-1:0),r=1;e>r;r++)n[r-1]=arguments[r];this._values.push(n)}},{key:"_toParamString",value:function(){var t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];return this._buildManyStrings(this._strings,this._values,t)}}]),i}(p.Block),p.registerValueHandler(p.FunctionBlock,function(t){var e=arguments.length<=1||void 0===arguments[1]?!1:arguments[1];return e?t.toParam():t.toString()}),p.AbstractTableBlock=function(o){function a(t,n){r(this,a);var i=e(this,Object.getPrototypeOf(a).call(this,t));return i._tables=[],i}return n(a,o),d(a,[{key:"_table",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?null:arguments[1];e=e?this._sanitizeTableAlias(e):e,t=this._sanitizeTable(t),this.options.singleTable&&(this._tables=[]),this._tables.push({table:t,alias:e})}},{key:"_hasTable",value:function(){return 0<this._tables.length}},{key:"_toParamString",value:function(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],n="",r=[];if(this._hasTable()){var o=!0,a=!1,l=void 0;try{for(var u,s=this._tables[Symbol.iterator]();!(o=(u=s.next()).done);o=!0){var c=u.value,f=c.table,h=c.alias;n=i(n,", ");var v=void 0;if(f instanceof p.BaseBuilder){var d=f._toParamString({buildParameterized:e.buildParameterized,nested:!0}),y=d.text,g=d.values;v=y,r.push.apply(r,t(g))}else v=this._formatTableName(f);h&&(v+=" "+this._formatTableAlias(h)),n+=v}}catch(_){a=!0,l=_}finally{try{!o&&s["return"]&&s["return"]()}finally{if(a)throw l}}this.options.prefix&&(n=this.options.prefix+" "+n)}return{text:n,values:r}}}]),a}(p.Block),p.TargetTableBlock=function(t){function i(){return r(this,i),e(this,Object.getPrototypeOf(i).apply(this,arguments))}return n(i,t),d(i,[{key:"target",value:function(t){this._table(t)}}]),i}(p.AbstractTableBlock),p.UpdateTableBlock=function(t){function i(){return r(this,i),e(this,Object.getPrototypeOf(i).apply(this,arguments))}return n(i,t),d(i,[{key:"table",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?null:arguments[1];this._table(t,e)}},{key:"_toParamString",value:function(){var t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];if(!this._hasTable())throw new Error("table() needs to be called");return v(Object.getPrototypeOf(i.prototype),"_toParamString",this).call(this,t)}}]),i}(p.AbstractTableBlock),p.FromTableBlock=function(t){function i(t){return r(this,i),e(this,Object.getPrototypeOf(i).call(this,o({},t,{prefix:"FROM"})))}return n(i,t),d(i,[{key:"from",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?null:arguments[1];this._table(t,e)}}]),i}(p.AbstractTableBlock),p.IntoTableBlock=function(t){function i(t){return r(this,i),e(this,Object.getPrototypeOf(i).call(this,o({},t,{prefix:"INTO",singleTable:!0})))}return n(i,t),d(i,[{key:"into",value:function(t){this._table(t)}},{key:"_toParamString",value:function(){var t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];if(!this._hasTable())throw new Error("into() needs to be called");return v(Object.getPrototypeOf(i.prototype),"_toParamString",this).call(this,t)}}]),i}(p.AbstractTableBlock),p.GetFieldBlock=function(o){function a(t){r(this,a);var n=e(this,Object.getPrototypeOf(a).call(this,t));return n._fields=[],n}return n(a,o),d(a,[{key:"fields",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];if(l(t)){var n=!0,r=!1,i=void 0;try{for(var o,a=t[Symbol.iterator]();!(n=(o=a.next()).done);n=!0){var u=o.value;this.field(u,null,e)}}catch(s){r=!0,i=s}finally{try{!n&&a["return"]&&a["return"]()}finally{if(r)throw i}}}else for(var c in t){var f=t[c];this.field(c,f,e)}}},{key:"field",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?null:arguments[1],n=arguments.length<=2||void 0===arguments[2]?{}:arguments[2];e=e?this._sanitizeFieldAlias(e):e,t=this._sanitizeField(t);var r=this._fields.filter(function(n){return n.name===t&&n.alias===e});return r.length?this:void this._fields.push({name:t,alias:e,options:n})}},{key:"_toParamString",value:function(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],n=e.queryBuilder,r=e.buildParameterized,o="",a=[],l=!0,u=!1,s=void 0;try{for(var c,f=this._fields[Symbol.iterator]();!(l=(c=f.next()).done);l=!0){var h=c.value;o=i(o,", ");var v=h.name,d=h.alias,y=h.options;if("string"==typeof v)o+=this._formatFieldName(v,y);else{var g=v._toParamString({nested:!0,buildParameterized:r});o+=g.text,a.push.apply(a,t(g.values))}d&&(o+=" AS "+this._formatFieldAlias(d))}}catch(_){u=!0,s=_}finally{try{!l&&f["return"]&&f["return"]()}finally{if(u)throw s}}if(!o.length){var m=n&&n.getBlock(p.FromTableBlock);m&&m._hasTable()&&(o="*")}return{text:o,values:a}}}]),a}(p.Block),p.AbstractSetFieldBlock=function(t){function i(t){r(this,i);var n=e(this,Object.getPrototypeOf(i).call(this,t));return n._reset(),n}return n(i,t),d(i,[{key:"_reset",value:function(){this._fields=[],this._values=[[]],this._valueOptions=[[]]}},{key:"_set",value:function(t,e){var n=arguments.length<=2||void 0===arguments[2]?{}:arguments[2];if(this._values.length>1)throw new Error("Cannot set multiple rows of fields this way.");"undefined"!=typeof e&&(e=this._sanitizeValue(e)),t=this._sanitizeField(t);var r=this._fields.indexOf(t);-1===r&&(this._fields.push(t),r=this._fields.length-1),this._values[0][r]=e,this._valueOptions[0][r]=n}},{key:"_setFields",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];if("object"!==("undefined"==typeof t?"undefined":y(t)))throw new Error("Expected an object but got "+("undefined"==typeof t?"undefined":y(t)));for(var n in t)this._set(n,t[n],e)}},{key:"_setFieldsRows",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];if(!l(t))throw new Error("Expected an array of objects but got "+("undefined"==typeof t?"undefined":y(t)));this._reset();for(var n=0;t.length>n;++n){var r=t[n];for(var i in r){var o=r[i];i=this._sanitizeField(i),o=this._sanitizeValue(o);var a=this._fields.indexOf(i);if(n>0&&-1===a)throw new Error("All fields in subsequent rows must match the fields in the first row");-1===a&&(this._fields.push(i),a=this._fields.length-1),l(this._values[n])||(this._values[n]=[],this._valueOptions[n]=[]),this._values[n][a]=o,this._valueOptions[n][a]=e}}}}]),i}(p.Block),p.SetFieldBlock=function(o){function a(){return r(this,a),e(this,Object.getPrototypeOf(a).apply(this,arguments))}return n(a,o),d(a,[{key:"set",value:function(t,e,n){this._set(t,e,n)}},{key:"setFields",value:function(t,e){this._setFields(t,e)}},{key:"_toParamString",value:function(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],n=e.buildParameterized;if(0>=this._fields.length)throw new Error("set() needs to be called");for(var r="",o=[],a=0;a<this._fields.length;++a){r=i(r,", ");var l=this._formatFieldName(this._fields[a]),u=this._values[0][a];0>l.indexOf("=")&&(l=l+" = "+this.options.parameterCharacter);var s=this._buildString(l,[u],{buildParameterized:n,formattingOptions:this._valueOptions[0][a]});r+=s.text,o.push.apply(o,t(s.values))}return{text:"SET "+r,values:o}}}]),a}(p.AbstractSetFieldBlock),p.InsertFieldValueBlock=function(o){function a(){return r(this,a),e(this,Object.getPrototypeOf(a).apply(this,arguments))}return n(a,o),d(a,[{key:"set",value:function(t,e){var n=arguments.length<=2||void 0===arguments[2]?{}:arguments[2];this._set(t,e,n)}},{key:"setFields",value:function(t,e){this._setFields(t,e)}},{key:"setFieldsRows",value:function(t,e){this._setFieldsRows(t,e)}},{key:"_toParamString",value:function(){for(var e=this,n=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],r=n.buildParameterized,o=this._fields.map(function(t){return e._formatFieldName(t)}).join(", "),a=[],l=[],u=0;u<this._values.length;++u){a[u]="";for(var s=0;s<this._values[u].length;++s){var c=this._buildString(this.options.parameterCharacter,[this._values[u][s]],{buildParameterized:r,formattingOptions:this._valueOptions[u][s]});l.push.apply(l,t(c.values)),a[u]=i(a[u],", "),a[u]+=c.text}}return{text:o.length?"("+o+") VALUES ("+a.join("), (")+")":"",values:l}}}]),a}(p.AbstractSetFieldBlock),p.InsertFieldsFromQueryBlock=function(t){function i(t){r(this,i);var n=e(this,Object.getPrototypeOf(i).call(this,t));return n._fields=[],n._query=null,n}return n(i,t),d(i,[{key:"fromQuery",value:function(t,e){var n=this;this._fields=t.map(function(t){return n._sanitizeField(t)}),this._query=this._sanitizeBaseBuilder(e)}},{key:"_toParamString",value:function(){var t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],e="",n=[];if(this._fields.length&&this._query){var r=this._query._toParamString({buildParameterized:t.buildParameterized,nested:!0}),i=r.text,o=r.values;e="("+this._fields.join(", ")+") "+this._applyNestingFormatting(i),n=o}return{text:e,values:n}}}]),i}(p.Block),p.DistinctBlock=function(t){function i(){return r(this,i),e(this,Object.getPrototypeOf(i).apply(this,arguments))}return n(i,t),d(i,[{key:"distinct",value:function(){this._useDistinct=!0}},{key:"_toParamString",value:function(){return{text:this._useDistinct?"DISTINCT":"",values:[]}}}]),i}(p.Block),p.GroupByBlock=function(t){function i(t){r(this,i);var n=e(this,Object.getPrototypeOf(i).call(this,t));return n._groups=[],n}return n(i,t),d(i,[{key:"group",value:function(t){this._groups.push(this._sanitizeField(t))}},{key:"_toParamString",value:function(){arguments.length<=0||void 0===arguments[0]?{}:arguments[0];return{text:this._groups.length?"GROUP BY "+this._groups.join(", "):"",values:[]}}}]),i}(p.Block),p.OffsetBlock=function(t){function i(t){r(this,i);var n=e(this,Object.getPrototypeOf(i).call(this,t));return n._offsets=null,n}return n(i,t),d(i,[{key:"offset",value:function(t){this._offsets=this._sanitizeLimitOffset(t)}},{key:"_toParamString",value:function(){return{text:this._offsets?"OFFSET "+this._offsets:"",values:[]}}}]),i}(p.Block),p.AbstractConditionBlock=function(i){function o(t){r(this,o);var n=e(this,Object.getPrototypeOf(o).call(this,t));return n._conditions=[],n}return n(o,i),d(o,[{key:"_condition",value:function(t){for(var e=arguments.length,n=Array(e>1?e-1:0),r=1;e>r;r++)n[r-1]=arguments[r];t=this._sanitizeExpression(t),this._conditions.push({expr:t,values:n})}},{key:"_toParamString",value:function(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],n=[],r=[],i=!0,o=!1,a=void 0;try{for(var l,u=this._conditions[Symbol.iterator]();!(i=(l=u.next()).done);i=!0){var s=l.value,c=s.expr,f=s.values,h=c instanceof p.Expression?c._toParamString({buildParameterized:e.buildParameterized}):this._buildString(c,f,{buildParameterized:e.buildParameterized});h.text.length&&n.push(h.text),r.push.apply(r,t(h.values))}}catch(v){o=!0,a=v}finally{try{!i&&u["return"]&&u["return"]()}finally{if(o)throw a}}return n.length&&(n=n.join(") AND (")),{text:n.length?this.options.verb+" ("+n+")":"",values:r}}}]),o}(p.Block),p.WhereBlock=function(t){function i(t){return r(this,i),e(this,Object.getPrototypeOf(i).call(this,o({},t,{verb:"WHERE"})))}return n(i,t),d(i,[{key:"where",value:function(t){for(var e=arguments.length,n=Array(e>1?e-1:0),r=1;e>r;r++)n[r-1]=arguments[r];this._condition.apply(this,[t].concat(n))}}]),i}(p.AbstractConditionBlock),p.HavingBlock=function(t){function i(t){return r(this,i),e(this,Object.getPrototypeOf(i).call(this,o({},t,{verb:"HAVING"})))}return n(i,t),d(i,[{key:"having",value:function(t){for(var e=arguments.length,n=Array(e>1?e-1:0),r=1;e>r;r++)n[r-1]=arguments[r];this._condition.apply(this,[t].concat(n))}}]),i}(p.AbstractConditionBlock),p.OrderByBlock=function(o){function a(t){r(this,a);var n=e(this,Object.getPrototypeOf(a).call(this,t));return n._orders=[],n}return n(a,o),d(a,[{key:"order",value:function(t,e){for(var n=arguments.length,r=Array(n>2?n-2:0),i=2;n>i;i++)r[i-2]=arguments[i];t=this._sanitizeField(t),"string"!=typeof e&&(void 0===e?e="ASC":null!==e&&(e=e?"ASC":"DESC")),this._orders.push({field:t,dir:e,values:r})}},{key:"_toParamString",value:function(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],n="",r=[],o=!0,a=!1,l=void 0;try{for(var u,s=this._orders[Symbol.iterator]();!(o=(u=s.next()).done);o=!0){var c=u.value,f=c.field,h=c.dir,v=c.values;n=i(n,", ");var d=this._buildString(f,v,{buildParameterized:e.buildParameterized});n+=d.text,r.push.apply(r,t(d.values)),null!==h&&(n+=" "+h)}}catch(y){a=!0,l=y}finally{try{!o&&s["return"]&&s["return"]()}finally{if(a)throw l}}return{text:n.length?"ORDER BY "+n:"",values:r}}}]),a}(p.Block),p.LimitBlock=function(t){function i(t){r(this,i);var n=e(this,Object.getPrototypeOf(i).call(this,t));return n._limit=null,n}return n(i,t),d(i,[{key:"limit",value:function(t){this._limit=this._sanitizeLimitOffset(t)}},{key:"_toParamString",value:function(){return{text:null!==this._limit?"LIMIT "+this._limit:"",values:[]}}}]),i}(p.Block),p.JoinBlock=function(o){function a(t){r(this,a);var n=e(this,Object.getPrototypeOf(a).call(this,t));return n._joins=[],n}return n(a,o),d(a,[{key:"join",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?null:arguments[1],n=arguments.length<=2||void 0===arguments[2]?null:arguments[2],r=arguments.length<=3||void 0===arguments[3]?"INNER":arguments[3];t=this._sanitizeTable(t,!0),e=e?this._sanitizeTableAlias(e):e,n=n?this._sanitizeExpression(n):n,this._joins.push({type:r,table:t,alias:e,condition:n})}},{key:"left_join",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?null:arguments[1],n=arguments.length<=2||void 0===arguments[2]?null:arguments[2];this.join(t,e,n,"LEFT")}},{key:"right_join",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?null:arguments[1],n=arguments.length<=2||void 0===arguments[2]?null:arguments[2];this.join(t,e,n,"RIGHT")}},{key:"outer_join",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?null:arguments[1],n=arguments.length<=2||void 0===arguments[2]?null:arguments[2];this.join(t,e,n,"OUTER")}},{key:"left_outer_join",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?null:arguments[1],n=arguments.length<=2||void 0===arguments[2]?null:arguments[2];this.join(t,e,n,"LEFT OUTER")}},{key:"full_join",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?null:arguments[1],n=arguments.length<=2||void 0===arguments[2]?null:arguments[2];this.join(t,e,n,"FULL")}},{key:"cross_join",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?null:arguments[1],n=arguments.length<=2||void 0===arguments[2]?null:arguments[2];this.join(t,e,n,"CROSS")}},{key:"_toParamString",value:function(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],n="",r=[],o=!0,a=!1,l=void 0;try{for(var u,s=this._joins[Symbol.iterator]();!(o=(u=s.next()).done);o=!0){var c=u.value,f=c.type,h=c.table,v=c.alias,d=c.condition;n=i(n,this.options.separator);var y=void 0;if(h instanceof p.BaseBuilder){var g=h._toParamString({buildParameterized:e.buildParameterized,nested:!0});r.push.apply(r,t(g.values)),y=g.text}else y=this._formatTableName(h);if(n+=f+" JOIN "+y,v&&(n+=" "+this._formatTableAlias(v)),d){n+=" ON ";var _=void 0;_=d instanceof p.Expression?d._toParamString({buildParameterized:e.buildParameterized}):this._buildString(d,[],{buildParameterized:e.buildParameterized}),n+=this._applyNestingFormatting(_.text),r.push.apply(r,t(_.values))}}}catch(m){a=!0,l=m}finally{try{!o&&s["return"]&&s["return"]()}finally{if(a)throw l}}return{text:n,values:r}}}]),a}(p.Block),p.UnionBlock=function(o){function a(t){r(this,a);var n=e(this,Object.getPrototypeOf(a).call(this,t));return n._unions=[],n}return n(a,o),d(a,[{key:"union",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?"UNION":arguments[1];t=this._sanitizeTable(t),this._unions.push({type:e,table:t})}},{key:"union_all",value:function(t){this.union(t,"UNION ALL")}},{key:"_toParamString",value:function(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],n="",r=[],o=!0,a=!1,l=void 0;try{for(var u,s=this._unions[Symbol.iterator]();!(o=(u=s.next()).done);o=!0){var c=u.value,f=c.type,h=c.table;n=i(n,this.options.separator);var v=void 0;if(h instanceof p.BaseBuilder){var d=h._toParamString({buildParameterized:e.buildParameterized,nested:!0});v=d.text,r.push.apply(r,t(d.values))}else n=this._formatTableName(h);n+=f+" "+v}}catch(y){a=!0,l=y}finally{try{!o&&s["return"]&&s["return"]()}finally{if(a)throw l}}return{text:n,values:r}}}]),a}(p.Block),p.QueryBuilder=function(i){function a(t,n){r(this,a);var i=e(this,Object.getPrototypeOf(a).call(this,t));i.blocks=n||[];var o=!0,l=!1,u=void 0;try{for(var s,c=i.blocks[Symbol.iterator]();!(o=(s=c.next()).done);o=!0){var f=s.value,h=f.exposedMethods();for(var v in h){var d=h[v];if(void 0!==i[v])throw new Error("Builder already has a builder method called: "+v);!function(t,e,n){i[e]=function(){for(var e=arguments.length,r=Array(e),o=0;e>o;o++)r[o]=arguments[o];return n.call.apply(n,[t].concat(r)),i}}(f,v,d)}}}catch(y){l=!0,u=y}finally{try{!o&&c["return"]&&c["return"]()}finally{if(l)throw u}}return i}return n(a,i),d(a,[{key:"registerValueHandler",value:function(t,e){var n=!0,r=!1,i=void 0;try{for(var o,l=this.blocks[Symbol.iterator]();!(n=(o=l.next()).done);n=!0){var u=o.value;u.registerValueHandler(t,e)}}catch(s){r=!0,i=s}finally{try{!n&&l["return"]&&l["return"]()}finally{if(r)throw i}}return v(Object.getPrototypeOf(a.prototype),"registerValueHandler",this).call(this,t,e),this}},{key:"updateOptions",value:function(t){this.options=o({},this.options,t);var e=!0,n=!1,r=void 0;try{for(var i,a=this.blocks[Symbol.iterator]();!(e=(i=a.next()).done);e=!0){var l=i.value;l.options=o({},l.options,t)}}catch(u){n=!0,r=u}finally{try{!e&&a["return"]&&a["return"]()}finally{if(n)throw r}}}},{key:"_toParamString",value:function(){var e,n=this,r=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];r=o({},this.options,r);var i=this.blocks.map(function(t){return t._toParamString({buildParameterized:r.buildParameterized,queryBuilder:n})}),a=i.map(function(t){return t.text}),l=i.map(function(t){return t.values}),u=a.filter(function(t){return 0<t.length}).join(r.separator),s=(e=[]).concat.apply(e,t(l));return r.nested||r.numberedParameters&&!function(){var t=void 0!==r.numberedParametersStartAt?r.numberedParametersStartAt:1,e=r.parameterCharacter.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&");u=u.replace(new RegExp(e,"g"),function(){return""+r.numberedParametersPrefix+t++})}(),{text:this._applyNestingFormatting(u,!!r.nested),values:s}}},{key:"clone",value:function(){var t=this.blocks.map(function(t){return t.clone()});return new this.constructor(this.options,t)}},{key:"getBlock",value:function(t){var e=this.blocks.filter(function(e){return e instanceof t});return e[0]}}]),a}(p.BaseBuilder),p.Select=function(t){function i(t){var n=arguments.length<=1||void 0===arguments[1]?null:arguments[1];return r(this,i),n=n||[new p.StringBlock(t,"SELECT"),new p.FunctionBlock(t),new p.DistinctBlock(t),new p.GetFieldBlock(t),new p.FromTableBlock(t),new p.JoinBlock(t),new p.WhereBlock(t),new p.GroupByBlock(t),new p.HavingBlock(t),new p.OrderByBlock(t),new p.LimitBlock(t),new p.OffsetBlock(t),new p.UnionBlock(t)],e(this,Object.getPrototypeOf(i).call(this,t,n))}return n(i,t),i}(p.QueryBuilder),p.Update=function(t){function i(t){var n=arguments.length<=1||void 0===arguments[1]?null:arguments[1];
-return r(this,i),n=n||[new p.StringBlock(t,"UPDATE"),new p.UpdateTableBlock(t),new p.SetFieldBlock(t),new p.WhereBlock(t),new p.OrderByBlock(t),new p.LimitBlock(t)],e(this,Object.getPrototypeOf(i).call(this,t,n))}return n(i,t),i}(p.QueryBuilder),p.Delete=function(t){function i(t){var n=arguments.length<=1||void 0===arguments[1]?null:arguments[1];return r(this,i),n=n||[new p.StringBlock(t,"DELETE"),new p.TargetTableBlock(t),new p.FromTableBlock(o({},t,{singleTable:!0})),new p.JoinBlock(t),new p.WhereBlock(t),new p.OrderByBlock(t),new p.LimitBlock(t)],e(this,Object.getPrototypeOf(i).call(this,t,n))}return n(i,t),i}(p.QueryBuilder),p.Insert=function(t){function i(t){var n=arguments.length<=1||void 0===arguments[1]?null:arguments[1];return r(this,i),n=n||[new p.StringBlock(t,"INSERT"),new p.IntoTableBlock(t),new p.InsertFieldValueBlock(t),new p.InsertFieldsFromQueryBlock(t)],e(this,Object.getPrototypeOf(i).call(this,t,n))}return n(i,t),i}(p.QueryBuilder);var g={VERSION:"5.4.1",flavour:h,expr:function(t){return new p.Expression(t)},"case":function(t,e){return new p.Case(t,e)},select:function(t,e){return new p.Select(t,e)},update:function(t,e){return new p.Update(t,e)},insert:function(t,e){return new p.Insert(t,e)},"delete":function(t,e){return new p.Delete(t,e)},str:function(){var t=new p.FunctionBlock;return t["function"].apply(t,arguments),t},registerValueHandler:p.registerValueHandler};return g.remove=g["delete"],g.cls=p,g}var v=function g(t,e,n){null===t&&(t=Function.prototype);var r=Object.getOwnPropertyDescriptor(t,e);if(void 0===r){var i=Object.getPrototypeOf(t);return null===i?void 0:g(i,e,n)}if("value"in r)return r.value;var o=r.get;if(void 0!==o)return o.call(n)},d=function(){function t(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(e,n,r){return n&&t(e.prototype,n),r&&t(e,r),e}}(),y="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol?"symbol":typeof t},p=h();return p.flavours={},p.useFlavour=function(){var t=arguments.length<=0||void 0===arguments[0]?null:arguments[0];if(!t)return p;if(p.flavours[t]instanceof Function){var e=h(t);return p.flavours[t].call(null,e),e.flavours=p.flavours,e.useFlavour=p.useFlavour,e}throw new Error("Flavour not available: "+t)},p.flavours.mssql=function(t){var a=t.cls;a.DefaultQueryBuilderOptions.replaceSingleQuotes=!0,a.DefaultQueryBuilderOptions.autoQuoteAliasNames=!1,a.DefaultQueryBuilderOptions.numberedParametersPrefix="@",t.registerValueHandler(Date,function(t){return"'"+t.getUTCFullYear()+"-"+(t.getUTCMonth()+1)+"-"+t.getUTCDate()+" "+t.getUTCHours()+":"+t.getUTCMinutes()+":"+t.getUTCSeconds()+"'"}),a.MssqlLimitOffsetTopBlock=function(t){function i(t){r(this,i);var o=e(this,Object.getPrototypeOf(i).call(this,t));o._limits=null,o._offsets=null;var l=function(t){t=this._sanitizeLimitOffset(t),this._parent._limits=t};return o.ParentBlock=function(t){function i(t){r(this,i);var n=e(this,Object.getPrototypeOf(i).call(this,t.options));return n._parent=t,n}return n(i,t),i}(a.Block),o.LimitBlock=function(t){function i(t){r(this,i);var n=e(this,Object.getPrototypeOf(i).call(this,t));return n.limit=l,n}return n(i,t),d(i,[{key:"_toParamString",value:function(){var t="";return this._parent._limits&&this._parent._offsets&&(t="FETCH NEXT "+this._parent._limits+" ROWS ONLY"),{text:t,values:[]}}}]),i}(o.ParentBlock),o.TopBlock=function(t){function i(t){r(this,i);var n=e(this,Object.getPrototypeOf(i).call(this,t));return n.top=l,n}return n(i,t),d(i,[{key:"_toParamString",value:function(){var t="";return this._parent._limits&&!this._parent._offsets&&(t="TOP ("+this._parent._limits+")"),{text:t,values:[]}}}]),i}(o.ParentBlock),o.OffsetBlock=function(t){function i(){return r(this,i),e(this,Object.getPrototypeOf(i).apply(this,arguments))}return n(i,t),d(i,[{key:"offset",value:function(t){this._parent._offsets=this._sanitizeLimitOffset(t)}},{key:"_toParamString",value:function(){var t="";return this._parent._offsets&&(t="OFFSET "+this._parent._offsets+" ROWS"),{text:t,values:[]}}}]),i}(o.ParentBlock),o}return n(i,t),d(i,[{key:"LIMIT",value:function(){return new this.LimitBlock(this)}},{key:"TOP",value:function(){return new this.TopBlock(this)}},{key:"OFFSET",value:function(){return new this.OffsetBlock(this)}}]),i}(a.Block),a.MssqlUpdateTopBlock=function(t){function i(t){r(this,i);var n=e(this,Object.getPrototypeOf(i).call(this,t));return n._limits=null,n.limit=n.top=function(t){n._limits=n._sanitizeLimitOffset(t)},n}return n(i,t),d(i,[{key:"_toParamString",value:function(){return{text:this._limits?"TOP ("+this._limits+")":"",values:[]}}}]),i}(a.Block),a.MssqlInsertFieldValueBlock=function(t){function i(t){r(this,i);var n=e(this,Object.getPrototypeOf(i).call(this,t));return n._outputs=[],n}return n(i,t),d(i,[{key:"output",value:function(t){var e=this;"string"==typeof t?this._outputs.push("INSERTED."+this._sanitizeField(t)):t.forEach(function(t){e._outputs.push("INSERTED."+e._sanitizeField(t))})}},{key:"_toParamString",value:function(t){var e=v(Object.getPrototypeOf(i.prototype),"_toParamString",this).call(this,t);if(e.text.length&&0<this._outputs.length){var n="OUTPUT "+this._outputs.join(", ")+" ",r=e.text.indexOf("VALUES");e.text=e.text.substr(0,r)+n+e.text.substr(r)}return e}}]),i}(a.InsertFieldValueBlock),a.MssqlUpdateDeleteOutputBlock=function(t){function o(t){r(this,o);var n=e(this,Object.getPrototypeOf(o).call(this,t));return n._outputs=[],n}return n(o,t),d(o,[{key:"outputs",value:function(t){for(var e in t)this.output(e,t[e])}},{key:"output",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?null:arguments[1];t=this._sanitizeField(t),e=e?this._sanitizeFieldAlias(e):e,this._outputs.push({name:this.options.forDelete?"DELETED."+t:"INSERTED."+t,alias:e})}},{key:"_toParamString",value:function(t){var e="";if(this._outputs.length){var n=!0,r=!1,o=void 0;try{for(var a,l=this._outputs[Symbol.iterator]();!(n=(a=l.next()).done);n=!0){var u=a.value;e=i(e,", "),e+=u.name,u.alias&&(e+=" AS "+this._formatFieldAlias(u.alias))}}catch(s){r=!0,o=s}finally{try{!n&&l["return"]&&l["return"]()}finally{if(r)throw o}}e="OUTPUT "+e}return{text:e,values:[]}}}]),o}(a.Block),a.Select=function(t){function i(t){var n=arguments.length<=1||void 0===arguments[1]?null:arguments[1];r(this,i);var o=new a.MssqlLimitOffsetTopBlock(t);return n=n||[new a.StringBlock(t,"SELECT"),new a.DistinctBlock(t),o.TOP(),new a.GetFieldBlock(t),new a.FromTableBlock(t),new a.JoinBlock(t),new a.WhereBlock(t),new a.GroupByBlock(t),new a.OrderByBlock(t),o.OFFSET(),o.LIMIT(),new a.UnionBlock(t)],e(this,Object.getPrototypeOf(i).call(this,t,n))}return n(i,t),i}(a.QueryBuilder),a.Update=function(t){function i(t){var n=arguments.length<=1||void 0===arguments[1]?null:arguments[1];return r(this,i),n=n||[new a.StringBlock(t,"UPDATE"),new a.MssqlUpdateTopBlock(t),new a.UpdateTableBlock(t),new a.SetFieldBlock(t),new a.MssqlUpdateDeleteOutputBlock(t),new a.WhereBlock(t)],e(this,Object.getPrototypeOf(i).call(this,t,n))}return n(i,t),i}(a.QueryBuilder),a.Delete=function(t){function i(t){var n=arguments.length<=1||void 0===arguments[1]?null:arguments[1];return r(this,i),n=n||[new a.StringBlock(t,"DELETE"),new a.TargetTableBlock(t),new a.FromTableBlock(o({},t,{singleTable:!0})),new a.JoinBlock(t),new a.MssqlUpdateDeleteOutputBlock(o({},t,{forDelete:!0})),new a.WhereBlock(t),new a.OrderByBlock(t),new a.LimitBlock(t)],e(this,Object.getPrototypeOf(i).call(this,t,n))}return n(i,t),i}(a.QueryBuilder),a.Insert=function(t){function i(t){var n=arguments.length<=1||void 0===arguments[1]?null:arguments[1];return r(this,i),n=n||[new a.StringBlock(t,"INSERT"),new a.IntoTableBlock(t),new a.MssqlInsertFieldValueBlock(t),new a.InsertFieldsFromQueryBlock(t)],e(this,Object.getPrototypeOf(i).call(this,t,n))}return n(i,t),i}(a.QueryBuilder)},p.flavours.mysql=function(o){var a=o.cls;a.MysqlOnDuplicateKeyUpdateBlock=function(o){function a(){return r(this,a),e(this,Object.getPrototypeOf(a).apply(this,arguments))}return n(a,o),d(a,[{key:"onDupUpdate",value:function(t,e,n){this._set(t,e,n)}},{key:"_toParamString",value:function(){for(var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],n="",r=[],o=0;o<this._fields.length;++o){n=i(n,", ");var a=this._fields[o],l=this._values[0][o],u=this._valueOptions[0][o];if("undefined"==typeof l)n+=a;else{var s=this._buildString(a+" = "+this.options.parameterCharacter,[l],{buildParameterized:e.buildParameterized,formattingOptions:u});n+=s.text,r.push.apply(r,t(s.values))}}return{text:n.length?"ON DUPLICATE KEY UPDATE "+n:"",values:r}}}]),a}(a.AbstractSetFieldBlock),a.Insert=function(t){function i(t){var n=arguments.length<=1||void 0===arguments[1]?null:arguments[1];return r(this,i),n=n||[new a.StringBlock(t,"INSERT"),new a.IntoTableBlock(t),new a.InsertFieldValueBlock(t),new a.InsertFieldsFromQueryBlock(t),new a.MysqlOnDuplicateKeyUpdateBlock(t)],e(this,Object.getPrototypeOf(i).call(this,t,n))}return n(i,t),i}(a.QueryBuilder),a.Replace=function(t){function i(t){var n=arguments.length<=1||void 0===arguments[1]?null:arguments[1];return r(this,i),n=n||[new a.StringBlock(t,"REPLACE"),new a.IntoTableBlock(t),new a.InsertFieldValueBlock(t),new a.InsertFieldsFromQueryBlock(t)],e(this,Object.getPrototypeOf(i).call(this,t,n))}return n(i,t),i}(a.QueryBuilder),o.replace=function(t,e){return new a.Replace(t,e)}},p.flavours.postgres=function(i){var a=i.cls;a.DefaultQueryBuilderOptions.numberedParameters=!0,a.DefaultQueryBuilderOptions.numberedParametersStartAt=1,a.DefaultQueryBuilderOptions.autoQuoteAliasNames=!1,a.DefaultQueryBuilderOptions.useAsForTableAliasNames=!0,a.ReturningBlock=function(t){function i(t){r(this,i);var n=e(this,Object.getPrototypeOf(i).call(this,t));return n._str=null,n}return n(i,t),d(i,[{key:"returning",value:function(t){this._str=this._sanitizeField(t)}},{key:"_toParamString",value:function(){return{text:this._str?"RETURNING "+this._str:"",values:[]}}}]),i}(a.Block),a.WithBlock=function(i){function o(t){r(this,o);var n=e(this,Object.getPrototypeOf(o).call(this,t));return n._tables=[],n}return n(o,i),d(o,[{key:"with",value:function(t,e){this._tables.push({alias:t,table:e})}},{key:"_toParamString",value:function(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],n=[],r=[],i=!0,o=!1,a=void 0;try{for(var l,u=this._tables[Symbol.iterator]();!(i=(l=u.next()).done);i=!0){var s=l.value,c=s.alias,f=s.table,h=f._toParamString({buildParameterized:e.buildParameterized,nested:!0});n.push(c+" AS "+h.text),r.push.apply(r,t(h.values))}}catch(v){o=!0,a=v}finally{try{!i&&u["return"]&&u["return"]()}finally{if(o)throw a}}return{text:n.length?"WITH "+n.join(", "):"",values:r}}}]),o}(a.Block),a.DistinctOnBlock=function(t){function i(t){r(this,i);var n=e(this,Object.getPrototypeOf(i).call(this,t));return n._distinctFields=[],n}return n(i,t),d(i,[{key:"distinct",value:function(){var t=this;this._useDistinct=!0;for(var e=arguments.length,n=Array(e),r=0;e>r;r++)n[r]=arguments[r];n.forEach(function(e){t._distinctFields.push(t._sanitizeField(e))})}},{key:"_toParamString",value:function(){var t="";return this._useDistinct&&(t="DISTINCT",this._distinctFields.length&&(t+=" ON ("+this._distinctFields.join(", ")+")")),{text:t,values:[]}}}]),i}(a.Block),a.Select=function(t){function i(t){var n=arguments.length<=1||void 0===arguments[1]?null:arguments[1];return r(this,i),n=n||[new a.WithBlock(t),new a.StringBlock(t,"SELECT"),new a.FunctionBlock(t),new a.DistinctOnBlock(t),new a.GetFieldBlock(t),new a.FromTableBlock(t),new a.JoinBlock(t),new a.WhereBlock(t),new a.GroupByBlock(t),new a.HavingBlock(t),new a.OrderByBlock(t),new a.LimitBlock(t),new a.OffsetBlock(t),new a.UnionBlock(t)],e(this,Object.getPrototypeOf(i).call(this,t,n))}return n(i,t),i}(a.QueryBuilder),a.Insert=function(t){function i(t){var n=arguments.length<=1||void 0===arguments[1]?null:arguments[1];return r(this,i),n=n||[new a.WithBlock(t),new a.StringBlock(t,"INSERT"),new a.IntoTableBlock(t),new a.InsertFieldValueBlock(t),new a.InsertFieldsFromQueryBlock(t),new a.ReturningBlock(t)],e(this,Object.getPrototypeOf(i).call(this,t,n))}return n(i,t),i}(a.QueryBuilder),a.Update=function(t){function i(t){var n=arguments.length<=1||void 0===arguments[1]?null:arguments[1];return r(this,i),n=n||[new a.WithBlock(t),new a.StringBlock(t,"UPDATE"),new a.UpdateTableBlock(t),new a.SetFieldBlock(t),new a.FromTableBlock(t),new a.WhereBlock(t),new a.OrderByBlock(t),new a.LimitBlock(t),new a.ReturningBlock(t)],e(this,Object.getPrototypeOf(i).call(this,t,n))}return n(i,t),i}(a.QueryBuilder),a.Delete=function(t){function i(t){var n=arguments.length<=1||void 0===arguments[1]?null:arguments[1];return r(this,i),n=n||[new a.WithBlock(t),new a.StringBlock(t,"DELETE"),new a.TargetTableBlock(t),new a.FromTableBlock(o({},t,{singleTable:!0})),new a.JoinBlock(t),new a.WhereBlock(t),new a.OrderByBlock(t),new a.LimitBlock(t),new a.ReturningBlock(t)],e(this,Object.getPrototypeOf(i).call(this,t,n))}return n(i,t),i}(a.QueryBuilder)},p});
+/*! squel | https://github.com/hiddentao/squel | BSD license */!function(t,e){"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?module.exports=e():t.squel=e()}(this,function(){"use strict";function t(t){if(Array.isArray(t)){for(var e=0,n=Array(t.length);e<t.length;e++)n[e]=t[e];return n}return Array.from(t)}function e(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function n(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}function r(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function i(t,e){return t.length?t+e:t}function o(t){for(var e=arguments.length,n=Array(e>1?e-1:0),r=1;e>r;r++)n[r-1]=arguments[r];if(t&&n){var i=!0,o=!1,a=void 0;try{for(var l,u=function(){var e=l.value;"object"===("undefined"==typeof e?"undefined":y(e))&&Object.getOwnPropertyNames(e).forEach(function(n){t[n]=e[n]})},s=n[Symbol.iterator]();!(i=(l=s.next()).done);i=!0)u()}catch(c){o=!0,a=c}finally{try{!i&&s["return"]&&s["return"]()}finally{if(o)throw a}}}return t}function a(t){return t&&t.constructor.prototype===Object.prototype}function l(t){return t&&t.constructor.prototype===Array.prototype}function u(t){if(t&&t.constructor&&t.constructor.toString){var e=t.constructor.toString().match(/function\s*(\w+)/);if(e&&2===e.length)return e[1]}}function s(t){if(!t)return t;if("function"==typeof t.clone)return t.clone();if(!a(t)&&!l(t))return JSON.parse(JSON.stringify(t));var e=function(){var e=new t.constructor;return Object.getOwnPropertyNames(t).forEach(function(n){"function"!=typeof t[n]&&(e[n]=s(t[n]))}),{v:e}}();return"object"===("undefined"==typeof e?"undefined":y(e))?e.v:void 0}function c(t,e,n){var r="undefined"==typeof e?"undefined":y(e);if("function"!==r&&"string"!==r)throw new Error("type must be a class constructor or string");if("function"!=typeof n)throw new Error("handler must be a function");var i=!0,o=!1,a=void 0;try{for(var l,u=t[Symbol.iterator]();!(i=(l=u.next()).done);i=!0){var s=l.value;if(s.type===e)return void(s.handler=n)}}catch(c){o=!0,a=c}finally{try{!i&&u["return"]&&u["return"]()}finally{if(o)throw a}}t.push({type:e,handler:n})}function f(t){for(var e=arguments.length,n=Array(e>1?e-1:0),r=1;e>r;r++)n[r-1]=arguments[r];var i=!0,o=!1,a=void 0;try{for(var l,u=n[Symbol.iterator]();!(i=(l=u.next()).done);i=!0){var s=l.value,c=!0,f=!1,h=void 0;try{for(var v,d=s[Symbol.iterator]();!(c=(v=d.next()).done);c=!0){var p=v.value;if(("undefined"==typeof t?"undefined":y(t))===p.type||"string"!=typeof p.type&&t instanceof p.type)return p.handler}}catch(g){f=!0,h=g}finally{try{!c&&d["return"]&&d["return"]()}finally{if(f)throw h}}}}catch(g){o=!0,a=g}finally{try{!i&&u["return"]&&u["return"]()}finally{if(o)throw a}}}function h(){var h=arguments.length<=0||void 0===arguments[0]?null:arguments[0],p={_getObjectClassName:u};p.DefaultQueryBuilderOptions={autoQuoteTableNames:!1,autoQuoteFieldNames:!1,autoQuoteAliasNames:!0,useAsForTableAliasNames:!1,nameQuoteCharacter:"`",tableAliasQuoteCharacter:"`",fieldAliasQuoteCharacter:'"',valueHandlers:[],parameterCharacter:"?",numberedParameters:!1,numberedParametersPrefix:"$",numberedParametersStartAt:1,replaceSingleQuotes:!1,singleQuoteReplacement:"''",separator:" ",stringFormatter:null},p.globalValueHandlers=[],p.registerValueHandler=function(t,e){c(p.globalValueHandlers,t,e)},p.Cloneable=function(){function t(){r(this,t)}return d(t,[{key:"clone",value:function(){var t=new this.constructor;return o(t,s(o({},this)))}}]),t}(),p.BaseBuilder=function(i){function a(t){r(this,a);var n=e(this,Object.getPrototypeOf(a).call(this)),i=JSON.parse(JSON.stringify(p.DefaultQueryBuilderOptions));return n.options=o({},i,t),n}return n(a,i),d(a,[{key:"registerValueHandler",value:function(t,e){return c(this.options.valueHandlers,t,e),this}},{key:"_sanitizeExpression",value:function(t){if(!(t instanceof p.BaseBuilder)&&"string"!=typeof t)throw new Error("expression must be a string or builder instance");return t}},{key:"_sanitizeName",value:function(t,e){if("string"!=typeof t)throw new Error(e+" must be a string");return t}},{key:"_sanitizeField",value:function(t){return t instanceof p.BaseBuilder||(t=this._sanitizeName(t,"field name")),t}},{key:"_sanitizeBaseBuilder",value:function(t){if(t instanceof p.BaseBuilder)return t;throw new Error("must be a builder instance")}},{key:"_sanitizeTable",value:function(t){if("string"!=typeof t)try{t=this._sanitizeBaseBuilder(t)}catch(e){throw new Error("table name must be a string or a builder")}else t=this._sanitizeName(t,"table");return t}},{key:"_sanitizeTableAlias",value:function(t){return this._sanitizeName(t,"table alias")}},{key:"_sanitizeFieldAlias",value:function(t){return this._sanitizeName(t,"field alias")}},{key:"_sanitizeLimitOffset",value:function(t){if(t=parseInt(t),0>t||isNaN(t))throw new Error("limit/offset must be >= 0");return t}},{key:"_sanitizeValue",value:function(t){var e="undefined"==typeof t?"undefined":y(t);if(null===t);else if("string"===e||"number"===e||"boolean"===e);else if(t instanceof p.BaseBuilder);else{var n=!!f(t,this.options.valueHandlers,p.globalValueHandlers);if(!n)throw new Error("field value must be a string, number, boolean, null or one of the registered custom value types")}return t}},{key:"_escapeValue",value:function(t){return this.options.replaceSingleQuotes?t.replace(/\'/g,this.options.singleQuoteReplacement):t}},{key:"_formatTableName",value:function(t){if(this.options.autoQuoteTableNames){var e=this.options.nameQuoteCharacter;t=""+e+t+e}return t}},{key:"_formatFieldAlias",value:function(t){if(this.options.autoQuoteAliasNames){var e=this.options.fieldAliasQuoteCharacter;t=""+e+t+e}return t}},{key:"_formatTableAlias",value:function(t){if(this.options.autoQuoteAliasNames){var e=this.options.tableAliasQuoteCharacter;t=""+e+t+e}return this.options.useAsForTableAliasNames?"AS "+t:t}},{key:"_formatFieldName",value:function(t){var e=this,n=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];return this.options.autoQuoteFieldNames&&!function(){var r=e.options.nameQuoteCharacter;t=n.ignorePeriodsForFieldNameQuotes?""+r+t+r:t.split(".").map(function(t){return"*"===t?t:""+r+t+r}).join(".")}(),t}},{key:"_formatCustomValue",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?!1:arguments[1],n=f(t,this.options.valueHandlers,p.globalValueHandlers);return n&&(t=n(t,e)),{formatted:!!n,value:t}}},{key:"_formatValueForParamArray",value:function(t){var e=this;return l(t)?t.map(function(t){return e._formatValueForParamArray(t)}):this._formatCustomValue(t,!0).value}},{key:"_formatValueForQueryString",value:function(t){var e=this,n=arguments.length<=1||void 0===arguments[1]?{}:arguments[1],r=this._formatCustomValue(t),i=r.formatted,o=r.value;if(i)return this._applyNestingFormatting(o);if(l(o))o=o.map(function(t){return e._formatValueForQueryString(t)}),o=this._applyNestingFormatting(o.join(", "));else{var a="undefined"==typeof o?"undefined":y(o);if(null===o)o="NULL";else if("boolean"===a)o=o?"TRUE":"FALSE";else if(o instanceof p.BaseBuilder)o=this._applyNestingFormatting(o.toString());else if("number"!==a){if("string"===a&&this.options.stringFormatter)return this.options.stringFormatter(o);if(n.dontQuote)o=""+o;else{var u=this._escapeValue(o);o="'"+u+"'"}}}return o}},{key:"_applyNestingFormatting",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?!0:arguments[1];return t&&"string"==typeof t&&e&&("("!==t.charAt(0)||")"!==t.charAt(t.length-1))?"("+t+")":t}},{key:"_buildString",value:function(e,n){var r=arguments.length<=2||void 0===arguments[2]?{}:arguments[2],i=r.nested,o=r.buildParameterized,a=r.formattingOptions;n=n||[],e=e||"";for(var u="",s=-1,c=[],f=this.options.parameterCharacter,h=0;e.length>h;)if(e.substr(h,f.length)===f){var v=n[++s];if(o)if(v instanceof p.BaseBuilder){var d=v._toParamString({buildParameterized:o,nested:!0});u+=d.text,c.push.apply(c,t(d.values))}else if(v=this._formatValueForParamArray(v),l(v)){var y=v.map(function(){return f}).join(", ");u+="("+y+")",c.push.apply(c,t(v))}else u+=f,c.push(v);else u+=this._formatValueForQueryString(v,a);h+=f.length}else u+=e.charAt(h),h++;return{text:this._applyNestingFormatting(u,!!i),values:c}}},{key:"_buildManyStrings",value:function(e,n){for(var r=arguments.length<=2||void 0===arguments[2]?{}:arguments[2],i=[],o=[],a=0;e.length>a;++a){var l=e[a],u=n[a],s=this._buildString(l,u,{buildParameterized:r.buildParameterized,nested:!1}),c=s.text,f=s.values;i.push(c),o.push.apply(o,t(f))}return i=i.join(this.options.separator),{text:i.length?this._applyNestingFormatting(i,!!r.nested):"",values:o}}},{key:"_toParamString",value:function(t){throw new Error("Not yet implemented")}},{key:"toString",value:function(){var t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];return this._toParamString(t).text}},{key:"toParam",value:function(){var t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];return this._toParamString(o({},t,{buildParameterized:!0}))}}]),a}(p.Cloneable),p.Expression=function(i){function o(t){r(this,o);var n=e(this,Object.getPrototypeOf(o).call(this,t));return n._nodes=[],n}return n(o,i),d(o,[{key:"and",value:function(t){for(var e=arguments.length,n=Array(e>1?e-1:0),r=1;e>r;r++)n[r-1]=arguments[r];return t=this._sanitizeExpression(t),this._nodes.push({type:"AND",expr:t,para:n}),this}},{key:"or",value:function(t){for(var e=arguments.length,n=Array(e>1?e-1:0),r=1;e>r;r++)n[r-1]=arguments[r];return t=this._sanitizeExpression(t),this._nodes.push({type:"OR",expr:t,para:n}),this}},{key:"_toParamString",value:function(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],n=[],r=[],i=!0,o=!1,a=void 0;try{for(var l,u=this._nodes[Symbol.iterator]();!(i=(l=u.next()).done);i=!0){var s=l.value,c=s.type,f=s.expr,h=s.para,v=f instanceof p.BaseBuilder?f._toParamString({buildParameterized:e.buildParameterized,nested:!0}):this._buildString(f,h,{buildParameterized:e.buildParameterized}),d=v.text,y=v.values;n.length&&n.push(c),n.push(d),r.push.apply(r,t(y))}}catch(g){o=!0,a=g}finally{try{!i&&u["return"]&&u["return"]()}finally{if(o)throw a}}return n=n.join(" "),{text:this._applyNestingFormatting(n,!!e.nested),values:r}}}]),o}(p.BaseBuilder),p.Case=function(l){function u(t){var n=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];r(this,u);var i=e(this,Object.getPrototypeOf(u).call(this,n));return a(t)&&(n=t,t=null),t&&(i._fieldName=i._sanitizeField(t)),i.options=o({},p.DefaultQueryBuilderOptions,n),i._cases=[],i._elseValue=null,i}return n(u,l),d(u,[{key:"when",value:function(t){for(var e=arguments.length,n=Array(e>1?e-1:0),r=1;e>r;r++)n[r-1]=arguments[r];return this._cases.unshift({expression:t,values:n}),this}},{key:"then",value:function(t){if(0==this._cases.length)throw new Error("when() needs to be called first");return this._cases[0].result=t,this}},{key:"else",value:function(t){return this._elseValue=t,this}},{key:"_toParamString",value:function(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],n="",r=[],o=!0,a=!1,l=void 0;try{for(var u,s=this._cases[Symbol.iterator]();!(o=(u=s.next()).done);o=!0){var c=u.value,f=c.expression,h=c.values,v=c.result;n=i(n," ");var d=this._buildString(f,h,{buildParameterized:e.buildParameterized,nested:!0});n+="WHEN "+d.text+" THEN "+this._formatValueForQueryString(v),r.push.apply(r,t(d.values))}}catch(y){a=!0,l=y}finally{try{!o&&s["return"]&&s["return"]()}finally{if(a)throw l}}return n.length?(n+=" ELSE "+this._formatValueForQueryString(this._elseValue)+" END",this._fieldName&&(n=this._fieldName+" "+n),n="CASE "+n):n=this._formatValueForQueryString(this._elseValue),{text:n,values:r}}}]),u}(p.BaseBuilder),p.Block=function(t){function i(t){return r(this,i),e(this,Object.getPrototypeOf(i).call(this,t))}return n(i,t),d(i,[{key:"exposedMethods",value:function(){for(var t={},e=this;e;)Object.getOwnPropertyNames(e).forEach(function(n){"constructor"===n||"function"!=typeof e[n]||"_"===n.charAt(0)||p.Block.prototype[n]||(t[n]=e[n])}),e=Object.getPrototypeOf(e);return t}}]),i}(p.BaseBuilder),p.StringBlock=function(t){function i(t,n){r(this,i);var o=e(this,Object.getPrototypeOf(i).call(this,t));return o._str=n,o}return n(i,t),d(i,[{key:"_toParamString",value:function(){arguments.length<=0||void 0===arguments[0]?{}:arguments[0];return{text:this._str,values:[]}}}]),i}(p.Block),p.FunctionBlock=function(t){function i(t){r(this,i);var n=e(this,Object.getPrototypeOf(i).call(this,t));return n._strings=[],n._values=[],n}return n(i,t),d(i,[{key:"function",value:function(t){this._strings.push(t);for(var e=arguments.length,n=Array(e>1?e-1:0),r=1;e>r;r++)n[r-1]=arguments[r];this._values.push(n)}},{key:"_toParamString",value:function(){var t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];return this._buildManyStrings(this._strings,this._values,t)}}]),i}(p.Block),p.registerValueHandler(p.FunctionBlock,function(t){var e=arguments.length<=1||void 0===arguments[1]?!1:arguments[1];return e?t.toParam():t.toString()}),p.AbstractTableBlock=function(o){function a(t,n){r(this,a);var i=e(this,Object.getPrototypeOf(a).call(this,t));return i._tables=[],i}return n(a,o),d(a,[{key:"_table",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?null:arguments[1];e=e?this._sanitizeTableAlias(e):e,t=this._sanitizeTable(t),this.options.singleTable&&(this._tables=[]),this._tables.push({table:t,alias:e})}},{key:"_hasTable",value:function(){return 0<this._tables.length}},{key:"_toParamString",value:function(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],n="",r=[];if(this._hasTable()){var o=!0,a=!1,l=void 0;try{for(var u,s=this._tables[Symbol.iterator]();!(o=(u=s.next()).done);o=!0){var c=u.value,f=c.table,h=c.alias;n=i(n,", ");var v=void 0;if(f instanceof p.BaseBuilder){var d=f._toParamString({buildParameterized:e.buildParameterized,nested:!0}),y=d.text,g=d.values;v=y,r.push.apply(r,t(g))}else v=this._formatTableName(f);h&&(v+=" "+this._formatTableAlias(h)),n+=v}}catch(_){a=!0,l=_}finally{try{!o&&s["return"]&&s["return"]()}finally{if(a)throw l}}this.options.prefix&&(n=this.options.prefix+" "+n)}return{text:n,values:r}}}]),a}(p.Block),p.TargetTableBlock=function(t){function i(){return r(this,i),e(this,Object.getPrototypeOf(i).apply(this,arguments))}return n(i,t),d(i,[{key:"target",value:function(t){this._table(t)}}]),i}(p.AbstractTableBlock),p.UpdateTableBlock=function(t){function i(){return r(this,i),e(this,Object.getPrototypeOf(i).apply(this,arguments))}return n(i,t),d(i,[{key:"table",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?null:arguments[1];this._table(t,e)}},{key:"_toParamString",value:function(){var t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];if(!this._hasTable())throw new Error("table() needs to be called");return v(Object.getPrototypeOf(i.prototype),"_toParamString",this).call(this,t)}}]),i}(p.AbstractTableBlock),p.FromTableBlock=function(t){function i(t){return r(this,i),e(this,Object.getPrototypeOf(i).call(this,o({},t,{prefix:"FROM"})))}return n(i,t),d(i,[{key:"from",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?null:arguments[1];this._table(t,e)}}]),i}(p.AbstractTableBlock),p.IntoTableBlock=function(t){function i(t){return r(this,i),e(this,Object.getPrototypeOf(i).call(this,o({},t,{prefix:"INTO",singleTable:!0})))}return n(i,t),d(i,[{key:"into",value:function(t){this._table(t)}},{key:"_toParamString",value:function(){var t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];if(!this._hasTable())throw new Error("into() needs to be called");return v(Object.getPrototypeOf(i.prototype),"_toParamString",this).call(this,t)}}]),i}(p.AbstractTableBlock),p.GetFieldBlock=function(o){function a(t){r(this,a);var n=e(this,Object.getPrototypeOf(a).call(this,t));return n._fields=[],n}return n(a,o),d(a,[{key:"fields",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];if(l(t)){var n=!0,r=!1,i=void 0;try{for(var o,a=t[Symbol.iterator]();!(n=(o=a.next()).done);n=!0){var u=o.value;this.field(u,null,e)}}catch(s){r=!0,i=s}finally{try{!n&&a["return"]&&a["return"]()}finally{if(r)throw i}}}else for(var c in t){var f=t[c];this.field(c,f,e)}}},{key:"field",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?null:arguments[1],n=arguments.length<=2||void 0===arguments[2]?{}:arguments[2];e=e?this._sanitizeFieldAlias(e):e,t=this._sanitizeField(t);var r=this._fields.filter(function(n){return n.name===t&&n.alias===e});return r.length?this:void this._fields.push({name:t,alias:e,options:n})}},{key:"_toParamString",value:function(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],n=e.queryBuilder,r=e.buildParameterized,o="",a=[],l=!0,u=!1,s=void 0;try{for(var c,f=this._fields[Symbol.iterator]();!(l=(c=f.next()).done);l=!0){var h=c.value;o=i(o,", ");var v=h.name,d=h.alias,y=h.options;if("string"==typeof v)o+=this._formatFieldName(v,y);else{var g=v._toParamString({nested:!0,buildParameterized:r});o+=g.text,a.push.apply(a,t(g.values))}d&&(o+=" AS "+this._formatFieldAlias(d))}}catch(_){u=!0,s=_}finally{try{!l&&f["return"]&&f["return"]()}finally{if(u)throw s}}if(!o.length){var m=n&&n.getBlock(p.FromTableBlock);m&&m._hasTable()&&(o="*")}return{text:o,values:a}}}]),a}(p.Block),p.AbstractSetFieldBlock=function(t){function i(t){r(this,i);var n=e(this,Object.getPrototypeOf(i).call(this,t));return n._reset(),n}return n(i,t),d(i,[{key:"_reset",value:function(){this._fields=[],this._values=[[]],this._valueOptions=[[]]}},{key:"_set",value:function(t,e){var n=arguments.length<=2||void 0===arguments[2]?{}:arguments[2];if(this._values.length>1)throw new Error("Cannot set multiple rows of fields this way.");"undefined"!=typeof e&&(e=this._sanitizeValue(e)),t=this._sanitizeField(t);var r=this._fields.indexOf(t);-1===r&&(this._fields.push(t),r=this._fields.length-1),this._values[0][r]=e,this._valueOptions[0][r]=n}},{key:"_setFields",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];if("object"!==("undefined"==typeof t?"undefined":y(t)))throw new Error("Expected an object but got "+("undefined"==typeof t?"undefined":y(t)));for(var n in t)this._set(n,t[n],e)}},{key:"_setFieldsRows",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];if(!l(t))throw new Error("Expected an array of objects but got "+("undefined"==typeof t?"undefined":y(t)));this._reset();for(var n=0;t.length>n;++n){var r=t[n];for(var i in r){var o=r[i];i=this._sanitizeField(i),o=this._sanitizeValue(o);var a=this._fields.indexOf(i);if(n>0&&-1===a)throw new Error("All fields in subsequent rows must match the fields in the first row");-1===a&&(this._fields.push(i),a=this._fields.length-1),l(this._values[n])||(this._values[n]=[],this._valueOptions[n]=[]),this._values[n][a]=o,this._valueOptions[n][a]=e}}}}]),i}(p.Block),p.SetFieldBlock=function(o){function a(){return r(this,a),e(this,Object.getPrototypeOf(a).apply(this,arguments))}return n(a,o),d(a,[{key:"set",value:function(t,e,n){this._set(t,e,n)}},{key:"setFields",value:function(t,e){this._setFields(t,e)}},{key:"_toParamString",value:function(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],n=e.buildParameterized;if(0>=this._fields.length)throw new Error("set() needs to be called");for(var r="",o=[],a=0;a<this._fields.length;++a){r=i(r,", ");var l=this._formatFieldName(this._fields[a]),u=this._values[0][a];0>l.indexOf("=")&&(l=l+" = "+this.options.parameterCharacter);var s=this._buildString(l,[u],{buildParameterized:n,formattingOptions:this._valueOptions[0][a]});r+=s.text,o.push.apply(o,t(s.values))}return{text:"SET "+r,values:o}}}]),a}(p.AbstractSetFieldBlock),p.InsertFieldValueBlock=function(o){function a(){return r(this,a),e(this,Object.getPrototypeOf(a).apply(this,arguments))}return n(a,o),d(a,[{key:"set",value:function(t,e){var n=arguments.length<=2||void 0===arguments[2]?{}:arguments[2];this._set(t,e,n)}},{key:"setFields",value:function(t,e){this._setFields(t,e)}},{key:"setFieldsRows",value:function(t,e){this._setFieldsRows(t,e)}},{key:"_toParamString",value:function(){for(var e=this,n=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],r=n.buildParameterized,o=this._fields.map(function(t){return e._formatFieldName(t)}).join(", "),a=[],l=[],u=0;u<this._values.length;++u){a[u]="";for(var s=0;s<this._values[u].length;++s){var c=this._buildString(this.options.parameterCharacter,[this._values[u][s]],{buildParameterized:r,formattingOptions:this._valueOptions[u][s]});l.push.apply(l,t(c.values)),a[u]=i(a[u],", "),a[u]+=c.text}}return{text:o.length?"("+o+") VALUES ("+a.join("), (")+")":"",values:l}}}]),a}(p.AbstractSetFieldBlock),p.InsertFieldsFromQueryBlock=function(t){function i(t){r(this,i);var n=e(this,Object.getPrototypeOf(i).call(this,t));return n._fields=[],n._query=null,n}return n(i,t),d(i,[{key:"fromQuery",value:function(t,e){var n=this;this._fields=t.map(function(t){return n._sanitizeField(t)}),this._query=this._sanitizeBaseBuilder(e)}},{key:"_toParamString",value:function(){var t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],e="",n=[];if(this._fields.length&&this._query){var r=this._query._toParamString({buildParameterized:t.buildParameterized,nested:!0}),i=r.text,o=r.values;e="("+this._fields.join(", ")+") "+this._applyNestingFormatting(i),n=o}return{text:e,values:n}}}]),i}(p.Block),p.DistinctBlock=function(t){function i(){return r(this,i),e(this,Object.getPrototypeOf(i).apply(this,arguments))}return n(i,t),d(i,[{key:"distinct",value:function(){this._useDistinct=!0}},{key:"_toParamString",value:function(){return{text:this._useDistinct?"DISTINCT":"",values:[]}}}]),i}(p.Block),p.GroupByBlock=function(t){function i(t){r(this,i);var n=e(this,Object.getPrototypeOf(i).call(this,t));return n._groups=[],n}return n(i,t),d(i,[{key:"group",value:function(t){this._groups.push(this._sanitizeField(t))}},{key:"_toParamString",value:function(){arguments.length<=0||void 0===arguments[0]?{}:arguments[0];return{text:this._groups.length?"GROUP BY "+this._groups.join(", "):"",values:[]}}}]),i}(p.Block),p.OffsetBlock=function(t){function i(t){r(this,i);var n=e(this,Object.getPrototypeOf(i).call(this,t));return n._offsets=null,n}return n(i,t),d(i,[{key:"offset",value:function(t){this._offsets=this._sanitizeLimitOffset(t)}},{key:"_toParamString",value:function(){return{text:this._offsets?"OFFSET "+this._offsets:"",values:[]}}}]),i}(p.Block),p.AbstractConditionBlock=function(i){function o(t){r(this,o);var n=e(this,Object.getPrototypeOf(o).call(this,t));return n._conditions=[],n}return n(o,i),d(o,[{key:"_condition",value:function(t){for(var e=arguments.length,n=Array(e>1?e-1:0),r=1;e>r;r++)n[r-1]=arguments[r];t=this._sanitizeExpression(t),this._conditions.push({expr:t,values:n})}},{key:"_toParamString",value:function(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],n=[],r=[],i=!0,o=!1,a=void 0;try{for(var l,u=this._conditions[Symbol.iterator]();!(i=(l=u.next()).done);i=!0){var s=l.value,c=s.expr,f=s.values,h=c instanceof p.BaseBuilder?c._toParamString({buildParameterized:e.buildParameterized}):this._buildString(c,f,{buildParameterized:e.buildParameterized});h.text.length&&n.push(h.text),r.push.apply(r,t(h.values))}}catch(v){o=!0,a=v}finally{try{!i&&u["return"]&&u["return"]()}finally{if(o)throw a}}return n.length&&(n=n.join(") AND (")),{text:n.length?this.options.verb+" ("+n+")":"",values:r}}}]),o}(p.Block),p.WhereBlock=function(t){function i(t){return r(this,i),e(this,Object.getPrototypeOf(i).call(this,o({},t,{verb:"WHERE"})))}return n(i,t),d(i,[{key:"where",value:function(t){for(var e=arguments.length,n=Array(e>1?e-1:0),r=1;e>r;r++)n[r-1]=arguments[r];this._condition.apply(this,[t].concat(n))}}]),i}(p.AbstractConditionBlock),p.HavingBlock=function(t){function i(t){return r(this,i),e(this,Object.getPrototypeOf(i).call(this,o({},t,{verb:"HAVING"})))}return n(i,t),d(i,[{key:"having",value:function(t){for(var e=arguments.length,n=Array(e>1?e-1:0),r=1;e>r;r++)n[r-1]=arguments[r];this._condition.apply(this,[t].concat(n))}}]),i}(p.AbstractConditionBlock),p.OrderByBlock=function(o){function a(t){r(this,a);var n=e(this,Object.getPrototypeOf(a).call(this,t));return n._orders=[],n}return n(a,o),d(a,[{key:"order",value:function(t,e){for(var n=arguments.length,r=Array(n>2?n-2:0),i=2;n>i;i++)r[i-2]=arguments[i];t=this._sanitizeField(t),"string"!=typeof e&&(void 0===e?e="ASC":null!==e&&(e=e?"ASC":"DESC")),this._orders.push({field:t,dir:e,values:r})}},{key:"_toParamString",value:function(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],n="",r=[],o=!0,a=!1,l=void 0;try{for(var u,s=this._orders[Symbol.iterator]();!(o=(u=s.next()).done);o=!0){var c=u.value,f=c.field,h=c.dir,v=c.values;n=i(n,", ");var d=this._buildString(f,v,{buildParameterized:e.buildParameterized});n+=d.text,r.push.apply(r,t(d.values)),null!==h&&(n+=" "+h)}}catch(y){a=!0,l=y}finally{try{!o&&s["return"]&&s["return"]()}finally{if(a)throw l}}return{text:n.length?"ORDER BY "+n:"",values:r}}}]),a}(p.Block),p.LimitBlock=function(t){function i(t){r(this,i);var n=e(this,Object.getPrototypeOf(i).call(this,t));return n._limit=null,n}return n(i,t),d(i,[{key:"limit",value:function(t){this._limit=this._sanitizeLimitOffset(t)}},{key:"_toParamString",value:function(){return{text:null!==this._limit?"LIMIT "+this._limit:"",values:[]}}}]),i}(p.Block),p.JoinBlock=function(o){function a(t){r(this,a);var n=e(this,Object.getPrototypeOf(a).call(this,t));return n._joins=[],n}return n(a,o),d(a,[{key:"join",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?null:arguments[1],n=arguments.length<=2||void 0===arguments[2]?null:arguments[2],r=arguments.length<=3||void 0===arguments[3]?"INNER":arguments[3];t=this._sanitizeTable(t,!0),e=e?this._sanitizeTableAlias(e):e,n=n?this._sanitizeExpression(n):n,this._joins.push({type:r,table:t,alias:e,condition:n})}},{key:"left_join",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?null:arguments[1],n=arguments.length<=2||void 0===arguments[2]?null:arguments[2];this.join(t,e,n,"LEFT")}},{key:"right_join",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?null:arguments[1],n=arguments.length<=2||void 0===arguments[2]?null:arguments[2];this.join(t,e,n,"RIGHT")}},{key:"outer_join",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?null:arguments[1],n=arguments.length<=2||void 0===arguments[2]?null:arguments[2];this.join(t,e,n,"OUTER")}},{key:"left_outer_join",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?null:arguments[1],n=arguments.length<=2||void 0===arguments[2]?null:arguments[2];this.join(t,e,n,"LEFT OUTER")}},{key:"full_join",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?null:arguments[1],n=arguments.length<=2||void 0===arguments[2]?null:arguments[2];this.join(t,e,n,"FULL")}},{key:"cross_join",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?null:arguments[1],n=arguments.length<=2||void 0===arguments[2]?null:arguments[2];this.join(t,e,n,"CROSS")}},{key:"_toParamString",value:function(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],n="",r=[],o=!0,a=!1,l=void 0;try{for(var u,s=this._joins[Symbol.iterator]();!(o=(u=s.next()).done);o=!0){var c=u.value,f=c.type,h=c.table,v=c.alias,d=c.condition;n=i(n,this.options.separator);var y=void 0;if(h instanceof p.BaseBuilder){var g=h._toParamString({buildParameterized:e.buildParameterized,nested:!0});r.push.apply(r,t(g.values)),y=g.text}else y=this._formatTableName(h);if(n+=f+" JOIN "+y,v&&(n+=" "+this._formatTableAlias(v)),d){n+=" ON ";var _=void 0;_=d instanceof p.BaseBuilder?d._toParamString({buildParameterized:e.buildParameterized}):this._buildString(d,[],{buildParameterized:e.buildParameterized}),n+=this._applyNestingFormatting(_.text),r.push.apply(r,t(_.values))}}}catch(m){a=!0,l=m}finally{try{!o&&s["return"]&&s["return"]()}finally{if(a)throw l}}return{text:n,values:r}}}]),a}(p.Block),p.UnionBlock=function(o){function a(t){r(this,a);var n=e(this,Object.getPrototypeOf(a).call(this,t));return n._unions=[],n}return n(a,o),d(a,[{key:"union",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?"UNION":arguments[1];t=this._sanitizeTable(t),this._unions.push({type:e,table:t})}},{key:"union_all",value:function(t){this.union(t,"UNION ALL")}},{key:"_toParamString",value:function(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],n="",r=[],o=!0,a=!1,l=void 0;try{for(var u,s=this._unions[Symbol.iterator]();!(o=(u=s.next()).done);o=!0){var c=u.value,f=c.type,h=c.table;n=i(n,this.options.separator);var v=void 0;if(h instanceof p.BaseBuilder){var d=h._toParamString({buildParameterized:e.buildParameterized,nested:!0});v=d.text,r.push.apply(r,t(d.values))}else n=this._formatTableName(h);n+=f+" "+v}}catch(y){a=!0,l=y}finally{try{!o&&s["return"]&&s["return"]()}finally{if(a)throw l}}return{text:n,values:r}}}]),a}(p.Block),p.QueryBuilder=function(i){function a(t,n){r(this,a);var i=e(this,Object.getPrototypeOf(a).call(this,t));i.blocks=n||[];var o=!0,l=!1,u=void 0;try{for(var s,c=i.blocks[Symbol.iterator]();!(o=(s=c.next()).done);o=!0){var f=s.value,h=f.exposedMethods();for(var v in h){var d=h[v];if(void 0!==i[v])throw new Error("Builder already has a builder method called: "+v);!function(t,e,n){i[e]=function(){for(var e=arguments.length,r=Array(e),o=0;e>o;o++)r[o]=arguments[o];return n.call.apply(n,[t].concat(r)),i}}(f,v,d)}}}catch(y){l=!0,u=y}finally{try{!o&&c["return"]&&c["return"]()}finally{if(l)throw u}}return i}return n(a,i),d(a,[{key:"registerValueHandler",value:function(t,e){var n=!0,r=!1,i=void 0;try{for(var o,l=this.blocks[Symbol.iterator]();!(n=(o=l.next()).done);n=!0){var u=o.value;u.registerValueHandler(t,e)}}catch(s){r=!0,i=s}finally{try{!n&&l["return"]&&l["return"]()}finally{if(r)throw i}}return v(Object.getPrototypeOf(a.prototype),"registerValueHandler",this).call(this,t,e),this}},{key:"updateOptions",value:function(t){this.options=o({},this.options,t);var e=!0,n=!1,r=void 0;try{for(var i,a=this.blocks[Symbol.iterator]();!(e=(i=a.next()).done);e=!0){var l=i.value;l.options=o({},l.options,t)}}catch(u){n=!0,r=u}finally{try{!e&&a["return"]&&a["return"]()}finally{if(n)throw r}}}},{key:"_toParamString",value:function(){var e,n=this,r=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];r=o({},this.options,r);var i=this.blocks.map(function(t){return t._toParamString({buildParameterized:r.buildParameterized,queryBuilder:n})}),a=i.map(function(t){return t.text}),l=i.map(function(t){return t.values}),u=a.filter(function(t){return 0<t.length}).join(r.separator),s=(e=[]).concat.apply(e,t(l));return r.nested||r.numberedParameters&&!function(){var t=void 0!==r.numberedParametersStartAt?r.numberedParametersStartAt:1,e=r.parameterCharacter.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&");u=u.replace(new RegExp(e,"g"),function(){return""+r.numberedParametersPrefix+t++})}(),{text:this._applyNestingFormatting(u,!!r.nested),values:s}}},{key:"clone",value:function(){var t=this.blocks.map(function(t){return t.clone()});return new this.constructor(this.options,t)}},{key:"getBlock",value:function(t){var e=this.blocks.filter(function(e){return e instanceof t});return e[0]}}]),a}(p.BaseBuilder),p.Select=function(t){function i(t){var n=arguments.length<=1||void 0===arguments[1]?null:arguments[1];return r(this,i),n=n||[new p.StringBlock(t,"SELECT"),new p.FunctionBlock(t),new p.DistinctBlock(t),new p.GetFieldBlock(t),new p.FromTableBlock(t),new p.JoinBlock(t),new p.WhereBlock(t),new p.GroupByBlock(t),new p.HavingBlock(t),new p.OrderByBlock(t),new p.LimitBlock(t),new p.OffsetBlock(t),new p.UnionBlock(t)],e(this,Object.getPrototypeOf(i).call(this,t,n))}return n(i,t),i}(p.QueryBuilder),p.Update=function(t){function i(t){var n=arguments.length<=1||void 0===arguments[1]?null:arguments[1];
+return r(this,i),n=n||[new p.StringBlock(t,"UPDATE"),new p.UpdateTableBlock(t),new p.SetFieldBlock(t),new p.WhereBlock(t),new p.OrderByBlock(t),new p.LimitBlock(t)],e(this,Object.getPrototypeOf(i).call(this,t,n))}return n(i,t),i}(p.QueryBuilder),p.Delete=function(t){function i(t){var n=arguments.length<=1||void 0===arguments[1]?null:arguments[1];return r(this,i),n=n||[new p.StringBlock(t,"DELETE"),new p.TargetTableBlock(t),new p.FromTableBlock(o({},t,{singleTable:!0})),new p.JoinBlock(t),new p.WhereBlock(t),new p.OrderByBlock(t),new p.LimitBlock(t)],e(this,Object.getPrototypeOf(i).call(this,t,n))}return n(i,t),i}(p.QueryBuilder),p.Insert=function(t){function i(t){var n=arguments.length<=1||void 0===arguments[1]?null:arguments[1];return r(this,i),n=n||[new p.StringBlock(t,"INSERT"),new p.IntoTableBlock(t),new p.InsertFieldValueBlock(t),new p.InsertFieldsFromQueryBlock(t)],e(this,Object.getPrototypeOf(i).call(this,t,n))}return n(i,t),i}(p.QueryBuilder);var g={VERSION:"5.4.2",flavour:h,expr:function(t){return new p.Expression(t)},"case":function(t,e){return new p.Case(t,e)},select:function(t,e){return new p.Select(t,e)},update:function(t,e){return new p.Update(t,e)},insert:function(t,e){return new p.Insert(t,e)},"delete":function(t,e){return new p.Delete(t,e)},str:function(){var t=new p.FunctionBlock;return t["function"].apply(t,arguments),t},registerValueHandler:p.registerValueHandler};return g.remove=g["delete"],g.cls=p,g}var v=function g(t,e,n){null===t&&(t=Function.prototype);var r=Object.getOwnPropertyDescriptor(t,e);if(void 0===r){var i=Object.getPrototypeOf(t);return null===i?void 0:g(i,e,n)}if("value"in r)return r.value;var o=r.get;if(void 0!==o)return o.call(n)},d=function(){function t(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(e,n,r){return n&&t(e.prototype,n),r&&t(e,r),e}}(),y="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol?"symbol":typeof t},p=h();return p.flavours={},p.useFlavour=function(){var t=arguments.length<=0||void 0===arguments[0]?null:arguments[0];if(!t)return p;if(p.flavours[t]instanceof Function){var e=h(t);return p.flavours[t].call(null,e),e.flavours=p.flavours,e.useFlavour=p.useFlavour,e}throw new Error("Flavour not available: "+t)},p.flavours.mssql=function(t){var a=t.cls;a.DefaultQueryBuilderOptions.replaceSingleQuotes=!0,a.DefaultQueryBuilderOptions.autoQuoteAliasNames=!1,a.DefaultQueryBuilderOptions.numberedParametersPrefix="@",t.registerValueHandler(Date,function(t){return"'"+t.getUTCFullYear()+"-"+(t.getUTCMonth()+1)+"-"+t.getUTCDate()+" "+t.getUTCHours()+":"+t.getUTCMinutes()+":"+t.getUTCSeconds()+"'"}),a.MssqlLimitOffsetTopBlock=function(t){function i(t){r(this,i);var o=e(this,Object.getPrototypeOf(i).call(this,t));o._limits=null,o._offsets=null;var l=function(t){t=this._sanitizeLimitOffset(t),this._parent._limits=t};return o.ParentBlock=function(t){function i(t){r(this,i);var n=e(this,Object.getPrototypeOf(i).call(this,t.options));return n._parent=t,n}return n(i,t),i}(a.Block),o.LimitBlock=function(t){function i(t){r(this,i);var n=e(this,Object.getPrototypeOf(i).call(this,t));return n.limit=l,n}return n(i,t),d(i,[{key:"_toParamString",value:function(){var t="";return this._parent._limits&&this._parent._offsets&&(t="FETCH NEXT "+this._parent._limits+" ROWS ONLY"),{text:t,values:[]}}}]),i}(o.ParentBlock),o.TopBlock=function(t){function i(t){r(this,i);var n=e(this,Object.getPrototypeOf(i).call(this,t));return n.top=l,n}return n(i,t),d(i,[{key:"_toParamString",value:function(){var t="";return this._parent._limits&&!this._parent._offsets&&(t="TOP ("+this._parent._limits+")"),{text:t,values:[]}}}]),i}(o.ParentBlock),o.OffsetBlock=function(t){function i(){return r(this,i),e(this,Object.getPrototypeOf(i).apply(this,arguments))}return n(i,t),d(i,[{key:"offset",value:function(t){this._parent._offsets=this._sanitizeLimitOffset(t)}},{key:"_toParamString",value:function(){var t="";return this._parent._offsets&&(t="OFFSET "+this._parent._offsets+" ROWS"),{text:t,values:[]}}}]),i}(o.ParentBlock),o}return n(i,t),d(i,[{key:"LIMIT",value:function(){return new this.LimitBlock(this)}},{key:"TOP",value:function(){return new this.TopBlock(this)}},{key:"OFFSET",value:function(){return new this.OffsetBlock(this)}}]),i}(a.Block),a.MssqlUpdateTopBlock=function(t){function i(t){r(this,i);var n=e(this,Object.getPrototypeOf(i).call(this,t));return n._limits=null,n.limit=n.top=function(t){n._limits=n._sanitizeLimitOffset(t)},n}return n(i,t),d(i,[{key:"_toParamString",value:function(){return{text:this._limits?"TOP ("+this._limits+")":"",values:[]}}}]),i}(a.Block),a.MssqlInsertFieldValueBlock=function(t){function i(t){r(this,i);var n=e(this,Object.getPrototypeOf(i).call(this,t));return n._outputs=[],n}return n(i,t),d(i,[{key:"output",value:function(t){var e=this;"string"==typeof t?this._outputs.push("INSERTED."+this._sanitizeField(t)):t.forEach(function(t){e._outputs.push("INSERTED."+e._sanitizeField(t))})}},{key:"_toParamString",value:function(t){var e=v(Object.getPrototypeOf(i.prototype),"_toParamString",this).call(this,t);if(e.text.length&&0<this._outputs.length){var n="OUTPUT "+this._outputs.join(", ")+" ",r=e.text.indexOf("VALUES");e.text=e.text.substr(0,r)+n+e.text.substr(r)}return e}}]),i}(a.InsertFieldValueBlock),a.MssqlUpdateDeleteOutputBlock=function(t){function o(t){r(this,o);var n=e(this,Object.getPrototypeOf(o).call(this,t));return n._outputs=[],n}return n(o,t),d(o,[{key:"outputs",value:function(t){for(var e in t)this.output(e,t[e])}},{key:"output",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?null:arguments[1];t=this._sanitizeField(t),e=e?this._sanitizeFieldAlias(e):e,this._outputs.push({name:this.options.forDelete?"DELETED."+t:"INSERTED."+t,alias:e})}},{key:"_toParamString",value:function(t){var e="";if(this._outputs.length){var n=!0,r=!1,o=void 0;try{for(var a,l=this._outputs[Symbol.iterator]();!(n=(a=l.next()).done);n=!0){var u=a.value;e=i(e,", "),e+=u.name,u.alias&&(e+=" AS "+this._formatFieldAlias(u.alias))}}catch(s){r=!0,o=s}finally{try{!n&&l["return"]&&l["return"]()}finally{if(r)throw o}}e="OUTPUT "+e}return{text:e,values:[]}}}]),o}(a.Block),a.Select=function(t){function i(t){var n=arguments.length<=1||void 0===arguments[1]?null:arguments[1];r(this,i);var o=new a.MssqlLimitOffsetTopBlock(t);return n=n||[new a.StringBlock(t,"SELECT"),new a.DistinctBlock(t),o.TOP(),new a.GetFieldBlock(t),new a.FromTableBlock(t),new a.JoinBlock(t),new a.WhereBlock(t),new a.GroupByBlock(t),new a.OrderByBlock(t),o.OFFSET(),o.LIMIT(),new a.UnionBlock(t)],e(this,Object.getPrototypeOf(i).call(this,t,n))}return n(i,t),i}(a.QueryBuilder),a.Update=function(t){function i(t){var n=arguments.length<=1||void 0===arguments[1]?null:arguments[1];return r(this,i),n=n||[new a.StringBlock(t,"UPDATE"),new a.MssqlUpdateTopBlock(t),new a.UpdateTableBlock(t),new a.SetFieldBlock(t),new a.MssqlUpdateDeleteOutputBlock(t),new a.WhereBlock(t)],e(this,Object.getPrototypeOf(i).call(this,t,n))}return n(i,t),i}(a.QueryBuilder),a.Delete=function(t){function i(t){var n=arguments.length<=1||void 0===arguments[1]?null:arguments[1];return r(this,i),n=n||[new a.StringBlock(t,"DELETE"),new a.TargetTableBlock(t),new a.FromTableBlock(o({},t,{singleTable:!0})),new a.JoinBlock(t),new a.MssqlUpdateDeleteOutputBlock(o({},t,{forDelete:!0})),new a.WhereBlock(t),new a.OrderByBlock(t),new a.LimitBlock(t)],e(this,Object.getPrototypeOf(i).call(this,t,n))}return n(i,t),i}(a.QueryBuilder),a.Insert=function(t){function i(t){var n=arguments.length<=1||void 0===arguments[1]?null:arguments[1];return r(this,i),n=n||[new a.StringBlock(t,"INSERT"),new a.IntoTableBlock(t),new a.MssqlInsertFieldValueBlock(t),new a.InsertFieldsFromQueryBlock(t)],e(this,Object.getPrototypeOf(i).call(this,t,n))}return n(i,t),i}(a.QueryBuilder)},p.flavours.mysql=function(o){var a=o.cls;a.MysqlOnDuplicateKeyUpdateBlock=function(o){function a(){return r(this,a),e(this,Object.getPrototypeOf(a).apply(this,arguments))}return n(a,o),d(a,[{key:"onDupUpdate",value:function(t,e,n){this._set(t,e,n)}},{key:"_toParamString",value:function(){for(var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],n="",r=[],o=0;o<this._fields.length;++o){n=i(n,", ");var a=this._fields[o],l=this._values[0][o],u=this._valueOptions[0][o];if("undefined"==typeof l)n+=a;else{var s=this._buildString(a+" = "+this.options.parameterCharacter,[l],{buildParameterized:e.buildParameterized,formattingOptions:u});n+=s.text,r.push.apply(r,t(s.values))}}return{text:n.length?"ON DUPLICATE KEY UPDATE "+n:"",values:r}}}]),a}(a.AbstractSetFieldBlock),a.Insert=function(t){function i(t){var n=arguments.length<=1||void 0===arguments[1]?null:arguments[1];return r(this,i),n=n||[new a.StringBlock(t,"INSERT"),new a.IntoTableBlock(t),new a.InsertFieldValueBlock(t),new a.InsertFieldsFromQueryBlock(t),new a.MysqlOnDuplicateKeyUpdateBlock(t)],e(this,Object.getPrototypeOf(i).call(this,t,n))}return n(i,t),i}(a.QueryBuilder),a.Replace=function(t){function i(t){var n=arguments.length<=1||void 0===arguments[1]?null:arguments[1];return r(this,i),n=n||[new a.StringBlock(t,"REPLACE"),new a.IntoTableBlock(t),new a.InsertFieldValueBlock(t),new a.InsertFieldsFromQueryBlock(t)],e(this,Object.getPrototypeOf(i).call(this,t,n))}return n(i,t),i}(a.QueryBuilder),o.replace=function(t,e){return new a.Replace(t,e)}},p.flavours.postgres=function(i){var a=i.cls;a.DefaultQueryBuilderOptions.numberedParameters=!0,a.DefaultQueryBuilderOptions.numberedParametersStartAt=1,a.DefaultQueryBuilderOptions.autoQuoteAliasNames=!1,a.DefaultQueryBuilderOptions.useAsForTableAliasNames=!0,a.ReturningBlock=function(t){function i(t){r(this,i);var n=e(this,Object.getPrototypeOf(i).call(this,t));return n._str=null,n}return n(i,t),d(i,[{key:"returning",value:function(t){this._str=this._sanitizeField(t)}},{key:"_toParamString",value:function(){return{text:this._str?"RETURNING "+this._str:"",values:[]}}}]),i}(a.Block),a.WithBlock=function(i){function o(t){r(this,o);var n=e(this,Object.getPrototypeOf(o).call(this,t));return n._tables=[],n}return n(o,i),d(o,[{key:"with",value:function(t,e){this._tables.push({alias:t,table:e})}},{key:"_toParamString",value:function(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],n=[],r=[],i=!0,o=!1,a=void 0;try{for(var l,u=this._tables[Symbol.iterator]();!(i=(l=u.next()).done);i=!0){var s=l.value,c=s.alias,f=s.table,h=f._toParamString({buildParameterized:e.buildParameterized,nested:!0});n.push(c+" AS "+h.text),r.push.apply(r,t(h.values))}}catch(v){o=!0,a=v}finally{try{!i&&u["return"]&&u["return"]()}finally{if(o)throw a}}return{text:n.length?"WITH "+n.join(", "):"",values:r}}}]),o}(a.Block),a.DistinctOnBlock=function(t){function i(t){r(this,i);var n=e(this,Object.getPrototypeOf(i).call(this,t));return n._distinctFields=[],n}return n(i,t),d(i,[{key:"distinct",value:function(){var t=this;this._useDistinct=!0;for(var e=arguments.length,n=Array(e),r=0;e>r;r++)n[r]=arguments[r];n.forEach(function(e){t._distinctFields.push(t._sanitizeField(e))})}},{key:"_toParamString",value:function(){var t="";return this._useDistinct&&(t="DISTINCT",this._distinctFields.length&&(t+=" ON ("+this._distinctFields.join(", ")+")")),{text:t,values:[]}}}]),i}(a.Block),a.Select=function(t){function i(t){var n=arguments.length<=1||void 0===arguments[1]?null:arguments[1];return r(this,i),n=n||[new a.WithBlock(t),new a.StringBlock(t,"SELECT"),new a.FunctionBlock(t),new a.DistinctOnBlock(t),new a.GetFieldBlock(t),new a.FromTableBlock(t),new a.JoinBlock(t),new a.WhereBlock(t),new a.GroupByBlock(t),new a.HavingBlock(t),new a.OrderByBlock(t),new a.LimitBlock(t),new a.OffsetBlock(t),new a.UnionBlock(t)],e(this,Object.getPrototypeOf(i).call(this,t,n))}return n(i,t),i}(a.QueryBuilder),a.Insert=function(t){function i(t){var n=arguments.length<=1||void 0===arguments[1]?null:arguments[1];return r(this,i),n=n||[new a.WithBlock(t),new a.StringBlock(t,"INSERT"),new a.IntoTableBlock(t),new a.InsertFieldValueBlock(t),new a.InsertFieldsFromQueryBlock(t),new a.ReturningBlock(t)],e(this,Object.getPrototypeOf(i).call(this,t,n))}return n(i,t),i}(a.QueryBuilder),a.Update=function(t){function i(t){var n=arguments.length<=1||void 0===arguments[1]?null:arguments[1];return r(this,i),n=n||[new a.WithBlock(t),new a.StringBlock(t,"UPDATE"),new a.UpdateTableBlock(t),new a.SetFieldBlock(t),new a.FromTableBlock(t),new a.WhereBlock(t),new a.OrderByBlock(t),new a.LimitBlock(t),new a.ReturningBlock(t)],e(this,Object.getPrototypeOf(i).call(this,t,n))}return n(i,t),i}(a.QueryBuilder),a.Delete=function(t){function i(t){var n=arguments.length<=1||void 0===arguments[1]?null:arguments[1];return r(this,i),n=n||[new a.WithBlock(t),new a.StringBlock(t,"DELETE"),new a.TargetTableBlock(t),new a.FromTableBlock(o({},t,{singleTable:!0})),new a.JoinBlock(t),new a.WhereBlock(t),new a.OrderByBlock(t),new a.LimitBlock(t),new a.ReturningBlock(t)],e(this,Object.getPrototypeOf(i).call(this,t,n))}return n(i,t),i}(a.QueryBuilder)},p});

0 comments on commit 2712581

Please sign in to comment.