New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

squel

Package Overview
Dependencies
Maintainers
1
Versions
78
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

squel - npm Package Compare versions

Comparing version 5.11.1 to 5.12.0

4

dist/squel-basic.min.js

@@ -1,2 +0,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,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 e(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 n(t,e){return t.length?t+e:t}function i(t){for(var e=arguments.length,r=Array(e>1?e-1:0),n=1;e>n;n++)r[n-1]=arguments[n];if(t&&r){var i=!0,a=!1,o=void 0;try{for(var l,u=function(){var e=l.value;"object"===("undefined"==typeof e?"undefined":d(e))&&Object.getOwnPropertyNames(e).forEach(function(r){t[r]=e[r]})},s=r[Symbol.iterator]();!(i=(l=s.next()).done);i=!0)u()}catch(f){a=!0,o=f}finally{try{!i&&s["return"]&&s["return"]()}finally{if(a)throw o}}}return t}function a(t){return t&&t.constructor.prototype===Object.prototype}function o(t){return t&&t.constructor.prototype===Array.prototype}function l(t){if(!t)return t;if("function"==typeof t.clone)return t.clone();if(!a(t)&&!o(t))return JSON.parse(JSON.stringify(t));var e=function(){var e=new t.constructor;return Object.getOwnPropertyNames(t).forEach(function(r){"function"!=typeof t[r]&&(e[r]=l(t[r]))}),{v:e}}();return"object"===("undefined"==typeof e?"undefined":d(e))?e.v:void 0}function u(t,e,r){var n="undefined"==typeof e?"undefined":d(e);if("function"!==n&&"string"!==n)throw new Error("type must be a class constructor or string");if("function"!=typeof r)throw new Error("handler must be a function");var i=!0,a=!1,o=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=r)}}catch(f){a=!0,o=f}finally{try{!i&&u["return"]&&u["return"]()}finally{if(a)throw o}}t.push({type:e,handler:r})}function s(t,e,r){return f(t,e)||f(t,r)}function f(t,e){for(var r=0;r<e.length;r++){var n=e[r];if(("undefined"==typeof t?"undefined":d(t))===n.type||"string"!=typeof n.type&&t instanceof n.type)return n.handler}}function c(){var f=arguments.length<=0||void 0===arguments[0]?null:arguments[0],c={isSquelBuilder:function(t){return t&&!!t._toParamString}},y=function(t){return!c.isSquelBuilder(t)||!t.options.rawNesting};c.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,rawNesting:!1},c.globalValueHandlers=[],c.registerValueHandler=function(t,e){u(c.globalValueHandlers,t,e)},c.Cloneable=function(){function t(){r(this,t)}return v(t,[{key:"clone",value:function(){var t=new this.constructor;return i(t,l(i({},this)))}}]),t}(),c.BaseBuilder=function(n){function a(e){r(this,a);var n=t(this,Object.getPrototypeOf(a).call(this)),o=JSON.parse(JSON.stringify(c.DefaultQueryBuilderOptions));return["stringFormatter"].forEach(function(t){o[t]=c.DefaultQueryBuilderOptions[t]}),n.options=i({},o,e),n}return e(a,n),v(a,[{key:"registerValueHandler",value:function(t,e){return u(this.options.valueHandlers,t,e),this}},{key:"_sanitizeExpression",value:function(t){if(!c.isSquelBuilder(t)&&"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 c.isSquelBuilder(t)||(t=this._sanitizeName(t,"field name")),t}},{key:"_sanitizeBaseBuilder",value:function(t){if(c.isSquelBuilder(t))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":d(t);if(null===t);else if("string"===e||"number"===e||"boolean"===e);else if(c.isSquelBuilder(t));else{var r=!!s(t,this.options.valueHandlers,c.globalValueHandlers);if(!r)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,r=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];return this.options.autoQuoteFieldNames&&!function(){var n=e.options.nameQuoteCharacter;t=r.ignorePeriodsForFieldNameQuotes?""+n+t+n:t.split(".").map(function(t){return"*"===t?t:""+n+t+n}).join(".")}(),t}},{key:"_formatCustomValue",value:function(t,e,r){var n=s(t,this.options.valueHandlers,c.globalValueHandlers);return n&&(t=n(t,e,r),t&&t.rawNesting)?{formatted:!0,rawNesting:!0,value:t.value}:{formatted:!!n,value:t}}},{key:"_formatValueForParamArray",value:function(t){var e=this,r=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];return o(t)?t.map(function(t){return e._formatValueForParamArray(t,r)}):this._formatCustomValue(t,!0,r).value}},{key:"_formatValueForQueryString",value:function(t){var e=this,r=arguments.length<=1||void 0===arguments[1]?{}:arguments[1],n=this._formatCustomValue(t,!1,r),i=n.rawNesting,a=n.formatted,l=n.value;if(a)return i?l:this._applyNestingFormatting(l,y(t));if(o(l))l=l.map(function(t){return e._formatValueForQueryString(t)}),l=this._applyNestingFormatting(l.join(", "),y(l));else{var u="undefined"==typeof l?"undefined":d(l);if(null===l)l="NULL";else if("boolean"===u)l=l?"TRUE":"FALSE";else if(c.isSquelBuilder(l))l=this._applyNestingFormatting(l.toString(),y(l));else if("number"!==u){if("string"===u&&this.options.stringFormatter)return this.options.stringFormatter(l);if(r.dontQuote)l=""+l;else{var s=this._escapeValue(l);l="'"+s+"'"}}}return l}},{key:"_applyNestingFormatting",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?!0:arguments[1];if(t&&"string"==typeof t&&e&&!this.options.rawNesting){var r="("===t.charAt(0)&&")"===t.charAt(t.length-1);if(r)for(var n=0,i=1;t.length-1>++n;){var a=t.charAt(n);if("("===a)i++;else if(")"===a&&(i--,1>i)){r=!1;break}}r||(t="("+t+")")}return t}},{key:"_buildString",value:function(t,e){var r=arguments.length<=2||void 0===arguments[2]?{}:arguments[2],n=r.nested,i=r.buildParameterized,a=r.formattingOptions;e=e||[],t=t||"";for(var l="",u=-1,s=[],f=this.options.parameterCharacter,h=0;t.length>h;)if(t.substr(h,f.length)===f){var v=e[++u];if(i)if(c.isSquelBuilder(v)){var d=v._toParamString({buildParameterized:i,nested:!0});l+=d.text,d.values.forEach(function(t){return s.push(t)})}else if(v=this._formatValueForParamArray(v,a),o(v)){var y=v.map(function(){return f}).join(", ");l+="("+y+")",v.forEach(function(t){return s.push(t)})}else l+=f,s.push(v);else l+=this._formatValueForQueryString(v,a);h+=f.length}else l+=t.charAt(h),h++;return{text:this._applyNestingFormatting(l,!!n),values:s}}},{key:"_buildManyStrings",value:function(t,e){for(var r=arguments.length<=2||void 0===arguments[2]?{}:arguments[2],n=[],i=[],a=0;t.length>a;++a){var o=t[a],l=e[a],u=this._buildString(o,l,{buildParameterized:r.buildParameterized,nested:!1}),s=u.text,f=u.values;n.push(s),f.forEach(function(t){return i.push(t)})}return n=n.join(this.options.separator),{text:n.length?this._applyNestingFormatting(n,!!r.nested):"",values:i}}},{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(i({},t,{buildParameterized:!0}))}}]),a}(c.Cloneable),c.Expression=function(n){function i(e){r(this,i);var n=t(this,Object.getPrototypeOf(i).call(this,e));return n._nodes=[],n}return e(i,n),v(i,[{key:"and",value:function(t){for(var e=arguments.length,r=Array(e>1?e-1:0),n=1;e>n;n++)r[n-1]=arguments[n];return t=this._sanitizeExpression(t),this._nodes.push({type:"AND",expr:t,para:r}),this}},{key:"or",value:function(t){for(var e=arguments.length,r=Array(e>1?e-1:0),n=1;e>n;n++)r[n-1]=arguments[n];return t=this._sanitizeExpression(t),this._nodes.push({type:"OR",expr:t,para:r}),this}},{key:"_toParamString",value:function(){var t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],e=[],r=[],n=!0,i=!1,a=void 0;try{for(var o,l=this._nodes[Symbol.iterator]();!(n=(o=l.next()).done);n=!0){var u=o.value,s=u.type,f=u.expr,h=u.para,v=c.isSquelBuilder(f)?f._toParamString({buildParameterized:t.buildParameterized,nested:!0}):this._buildString(f,h,{buildParameterized:t.buildParameterized}),d=v.text,y=v.values;e.length&&e.push(s),e.push(d),y.forEach(function(t){return r.push(t)})}}catch(p){i=!0,a=p}finally{try{!n&&l["return"]&&l["return"]()}finally{if(i)throw a}}return e=e.join(" "),{text:this._applyNestingFormatting(e,!!t.nested),values:r}}}]),i}(c.BaseBuilder),c.Case=function(o){function l(e){var n=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];r(this,l);var o=t(this,Object.getPrototypeOf(l).call(this,n));return a(e)&&(n=e,e=null),e&&(o._fieldName=o._sanitizeField(e)),o.options=i({},c.DefaultQueryBuilderOptions,n),o._cases=[],o._elseValue=null,o}return e(l,o),v(l,[{key:"when",value:function(t){for(var e=arguments.length,r=Array(e>1?e-1:0),n=1;e>n;n++)r[n-1]=arguments[n];return this._cases.unshift({expression:t,values:r||[]}),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 t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],e="",r=[],i=!0,a=!1,o=void 0;try{for(var l,u=this._cases[Symbol.iterator]();!(i=(l=u.next()).done);i=!0){var s=l.value,f=s.expression,c=s.values,h=s.result;e=n(e," ");var v=this._buildString(f,c,{buildParameterized:t.buildParameterized,nested:!0});e+="WHEN "+v.text+" THEN "+this._formatValueForQueryString(h),v.values.forEach(function(t){return r.push(t)})}}catch(d){a=!0,o=d}finally{try{!i&&u["return"]&&u["return"]()}finally{if(a)throw o}}return e.length?(e+=" ELSE "+this._formatValueForQueryString(this._elseValue)+" END",this._fieldName&&(e=this._fieldName+" "+e),e="CASE "+e):e=this._formatValueForQueryString(this._elseValue),{text:e,values:r}}}]),l}(c.BaseBuilder),c.Block=function(n){function i(e){return r(this,i),t(this,Object.getPrototypeOf(i).call(this,e))}return e(i,n),v(i,[{key:"exposedMethods",value:function(){for(var t={},e=this;e;)Object.getOwnPropertyNames(e).forEach(function(r){"constructor"===r||"function"!=typeof e[r]||"_"===r.charAt(0)||c.Block.prototype[r]||(t[r]=e[r])}),e=Object.getPrototypeOf(e);return t}}]),i}(c.BaseBuilder),c.StringBlock=function(n){function i(e,n){r(this,i);var a=t(this,Object.getPrototypeOf(i).call(this,e));return a._str=n,a}return e(i,n),v(i,[{key:"_toParamString",value:function(){arguments.length<=0||void 0===arguments[0]?{}:arguments[0];return{text:this._str,values:[]}}}]),i}(c.Block),c.FunctionBlock=function(n){function i(e){r(this,i);var n=t(this,Object.getPrototypeOf(i).call(this,e));return n._strings=[],n._values=[],n}return e(i,n),v(i,[{key:"function",value:function(t){this._strings.push(t);for(var e=arguments.length,r=Array(e>1?e-1:0),n=1;e>n;n++)r[n-1]=arguments[n];this._values.push(r)}},{key:"_toParamString",value:function(){var t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];return this._buildManyStrings(this._strings,this._values,t)}}]),i}(c.Block),c.registerValueHandler(c.FunctionBlock,function(t){var e=arguments.length<=1||void 0===arguments[1]?!1:arguments[1];return e?t.toParam():t.toString()}),c.AbstractTableBlock=function(i){function a(e,n){r(this,a);var i=t(this,Object.getPrototypeOf(a).call(this,e));return i._tables=[],i}return e(a,i),v(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 t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],e="",r=[];if(this._hasTable()){var i=!0,a=!1,o=void 0;try{for(var l,u=this._tables[Symbol.iterator]();!(i=(l=u.next()).done);i=!0){var s=l.value,f=s.table,h=s.alias;e=n(e,", ");var v=void 0;if(c.isSquelBuilder(f)){var d=f._toParamString({buildParameterized:t.buildParameterized,nested:!0}),y=d.text,p=d.values;v=y,p.forEach(function(t){return r.push(t)})}else v=this._formatTableName(f);h&&(v+=" "+this._formatTableAlias(h)),e+=v}}catch(g){a=!0,o=g}finally{try{!i&&u["return"]&&u["return"]()}finally{if(a)throw o}}this.options.prefix&&(e=this.options.prefix+" "+e)}return{text:e,values:r}}}]),a}(c.Block),c.TargetTableBlock=function(n){function i(){return r(this,i),t(this,Object.getPrototypeOf(i).apply(this,arguments))}return e(i,n),v(i,[{key:"target",value:function(t){this._table(t)}}]),i}(c.AbstractTableBlock),c.UpdateTableBlock=function(n){function i(){return r(this,i),t(this,Object.getPrototypeOf(i).apply(this,arguments))}return e(i,n),v(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 h(Object.getPrototypeOf(i.prototype),"_toParamString",this).call(this,t)}}]),i}(c.AbstractTableBlock),c.FromTableBlock=function(n){function a(e){return r(this,a),t(this,Object.getPrototypeOf(a).call(this,i({},e,{prefix:"FROM"})))}return e(a,n),v(a,[{key:"from",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?null:arguments[1];this._table(t,e)}}]),a}(c.AbstractTableBlock),c.IntoTableBlock=function(n){function a(e){return r(this,a),t(this,Object.getPrototypeOf(a).call(this,i({},e,{prefix:"INTO",singleTable:!0})))}return e(a,n),v(a,[{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 h(Object.getPrototypeOf(a.prototype),"_toParamString",this).call(this,t)}}]),a}(c.AbstractTableBlock),c.GetFieldBlock=function(i){function a(e){r(this,a);var n=t(this,Object.getPrototypeOf(a).call(this,e));return n._fields=[],n}return e(a,i),v(a,[{key:"fields",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];if(o(t)){var r=!0,n=!1,i=void 0;try{for(var a,l=t[Symbol.iterator]();!(r=(a=l.next()).done);r=!0){var u=a.value;this.field(u,null,e)}}catch(s){n=!0,i=s}finally{try{!r&&l["return"]&&l["return"]()}finally{if(n)throw i}}}else for(var f in t){var c=t[f];this.field(f,c,e)}}},{key:"field",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?null:arguments[1],r=arguments.length<=2||void 0===arguments[2]?{}:arguments[2];e=e?this._sanitizeFieldAlias(e):e,t=this._sanitizeField(t);var n=this._fields.filter(function(r){return r.name===t&&r.alias===e});return n.length?this:void this._fields.push({name:t,alias:e,options:r})}},{key:"_toParamString",value:function(){var t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],e=t.queryBuilder,r=t.buildParameterized,i="",a=[],o=!0,l=!1,u=void 0;try{for(var s,f=this._fields[Symbol.iterator]();!(o=(s=f.next()).done);o=!0){var h=s.value;i=n(i,", ");var v=h.name,d=h.alias,y=h.options;if("string"==typeof v)i+=this._formatFieldName(v,y);else{var p=v._toParamString({nested:!0,buildParameterized:r});i+=p.text,p.values.forEach(function(t){return a.push(t)})}d&&(i+=" AS "+this._formatFieldAlias(d))}}catch(g){l=!0,u=g}finally{try{!o&&f["return"]&&f["return"]()}finally{if(l)throw u}}if(!i.length){var b=e&&e.getBlock(c.FromTableBlock);b&&b._hasTable()&&(i="*")}return{text:i,values:a}}}]),a}(c.Block),c.AbstractSetFieldBlock=function(n){function i(e){r(this,i);var n=t(this,Object.getPrototypeOf(i).call(this,e));return n._reset(),n}return e(i,n),v(i,[{key:"_reset",value:function(){this._fields=[],this._values=[[]],this._valueOptions=[[]]}},{key:"_set",value:function(t,e){var r=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 n=this._fields.indexOf(t);-1===n&&(this._fields.push(t),n=this._fields.length-1),this._values[0][n]=e,this._valueOptions[0][n]=r}},{key:"_setFields",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];if("object"!==("undefined"==typeof t?"undefined":d(t)))throw new Error("Expected an object but got "+("undefined"==typeof t?"undefined":d(t)));for(var r in t)this._set(r,t[r],e)}},{key:"_setFieldsRows",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];if(!o(t))throw new Error("Expected an array of objects but got "+("undefined"==typeof t?"undefined":d(t)));this._reset();for(var r=0;t.length>r;++r){var n=t[r];for(var i in n){var a=n[i];i=this._sanitizeField(i),a=this._sanitizeValue(a);var l=this._fields.indexOf(i);if(r>0&&-1===l)throw new Error("All fields in subsequent rows must match the fields in the first row");-1===l&&(this._fields.push(i),l=this._fields.length-1),o(this._values[r])||(this._values[r]=[],this._valueOptions[r]=[]),this._values[r][l]=a,this._valueOptions[r][l]=e}}}}]),i}(c.Block),c.SetFieldBlock=function(i){function a(){return r(this,a),t(this,Object.getPrototypeOf(a).apply(this,arguments))}return e(a,i),v(a,[{key:"set",value:function(t,e,r){this._set(t,e,r)}},{key:"setFields",value:function(t,e){this._setFields(t,e)}},{key:"_toParamString",value:function(){var t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],e=t.buildParameterized;if(0>=this._fields.length)throw new Error("set() needs to be called");for(var r="",i=[],a=0;a<this._fields.length;++a){r=n(r,", ");var o=this._formatFieldName(this._fields[a]),l=this._values[0][a];0>o.indexOf("=")&&(o=o+" = "+this.options.parameterCharacter);var u=this._buildString(o,[l],{buildParameterized:e,formattingOptions:this._valueOptions[0][a]});r+=u.text,u.values.forEach(function(t){return i.push(t)})}return{text:"SET "+r,values:i}}}]),a}(c.AbstractSetFieldBlock),c.InsertFieldValueBlock=function(i){function a(){return r(this,a),t(this,Object.getPrototypeOf(a).apply(this,arguments))}return e(a,i),v(a,[{key:"set",value:function(t,e){var r=arguments.length<=2||void 0===arguments[2]?{}:arguments[2];this._set(t,e,r)}},{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 t=this,e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],r=e.buildParameterized,i=this._fields.map(function(e){return t._formatFieldName(e)}).join(", "),a=[],o=[],l=0;l<this._values.length;++l){a[l]="";for(var u=0;u<this._values[l].length;++u){var s=this._buildString(this.options.parameterCharacter,[this._values[l][u]],{buildParameterized:r,formattingOptions:this._valueOptions[l][u]});s.values.forEach(function(t){return o.push(t)}),a[l]=n(a[l],", "),a[l]+=s.text}}return{text:i.length?"("+i+") VALUES ("+a.join("), (")+")":"",values:o}}}]),a}(c.AbstractSetFieldBlock),c.InsertFieldsFromQueryBlock=function(n){function i(e){r(this,i);var n=t(this,Object.getPrototypeOf(i).call(this,e));return n._fields=[],n._query=null,n}return e(i,n),v(i,[{key:"fromQuery",value:function(t,e){var r=this;this._fields=t.map(function(t){return r._sanitizeField(t)}),this._query=this._sanitizeBaseBuilder(e)}},{key:"_toParamString",value:function(){var t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],e="",r=[];if(this._fields.length&&this._query){var n=this._query._toParamString({buildParameterized:t.buildParameterized,nested:!0}),i=n.text,a=n.values;e="("+this._fields.join(", ")+") "+this._applyNestingFormatting(i),r=a}return{text:e,values:r}}}]),i}(c.Block),c.DistinctBlock=function(n){function i(){return r(this,i),t(this,Object.getPrototypeOf(i).apply(this,arguments))}return e(i,n),v(i,[{key:"distinct",value:function(){this._useDistinct=!0}},{key:"_toParamString",value:function(){return{text:this._useDistinct?"DISTINCT":"",values:[]}}}]),i}(c.Block),c.GroupByBlock=function(n){function i(e){r(this,i);var n=t(this,Object.getPrototypeOf(i).call(this,e));return n._groups=[],n}return e(i,n),v(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}(c.Block),c.AbstractVerbSingleValueBlock=function(n){function i(e){r(this,i);var n=t(this,Object.getPrototypeOf(i).call(this,e));return n._value=null,n}return e(i,n),v(i,[{key:"_setValue",value:function(t){this._value=this._sanitizeLimitOffset(t)}},{key:"_toParamString",value:function(){var t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],e=null!==this._value?this.options.verb+" "+this.options.parameterCharacter:"",r=null!==this._value?[this._value]:[];return this._buildString(e,r,t)}}]),i}(c.Block),c.OffsetBlock=function(n){function a(e){return r(this,a),t(this,Object.getPrototypeOf(a).call(this,i({},e,{verb:"OFFSET"})))}return e(a,n),v(a,[{key:"offset",value:function(t){this._setValue(t)}}]),a}(c.AbstractVerbSingleValueBlock),c.LimitBlock=function(n){function a(e){return r(this,a),t(this,Object.getPrototypeOf(a).call(this,i({},e,{verb:"LIMIT"})))}return e(a,n),v(a,[{key:"limit",value:function(t){this._setValue(t)}}]),a}(c.AbstractVerbSingleValueBlock),c.AbstractConditionBlock=function(n){function i(e){r(this,i);var n=t(this,Object.getPrototypeOf(i).call(this,e));return n._conditions=[],n}return e(i,n),v(i,[{key:"_condition",value:function(t){t=this._sanitizeExpression(t);for(var e=arguments.length,r=Array(e>1?e-1:0),n=1;e>n;n++)r[n-1]=arguments[n];this._conditions.push({expr:t,values:r||[]})}},{key:"_toParamString",value:function(){var t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],e=[],r=[],n=!0,i=!1,a=void 0;try{for(var o,l=this._conditions[Symbol.iterator]();!(n=(o=l.next()).done);n=!0){var u=o.value,s=u.expr,f=u.values,h=c.isSquelBuilder(s)?s._toParamString({buildParameterized:t.buildParameterized}):this._buildString(s,f,{buildParameterized:t.buildParameterized});h.text.length&&e.push(h.text),h.values.forEach(function(t){return r.push(t)})}}catch(v){i=!0,a=v}finally{try{!n&&l["return"]&&l["return"]()}finally{if(i)throw a}}return e.length&&(e=e.join(") AND (")),{text:e.length?this.options.verb+" ("+e+")":"",values:r}}}]),i}(c.Block),c.WhereBlock=function(n){function a(e){return r(this,a),t(this,Object.getPrototypeOf(a).call(this,i({},e,{verb:"WHERE"})))}return e(a,n),v(a,[{key:"where",value:function(t){for(var e=arguments.length,r=Array(e>1?e-1:0),n=1;e>n;n++)r[n-1]=arguments[n];this._condition.apply(this,[t].concat(r))}}]),a}(c.AbstractConditionBlock),c.HavingBlock=function(n){function a(e){return r(this,a),t(this,Object.getPrototypeOf(a).call(this,i({},e,{verb:"HAVING"})))}return e(a,n),v(a,[{key:"having",value:function(t){for(var e=arguments.length,r=Array(e>1?e-1:0),n=1;e>n;n++)r[n-1]=arguments[n];this._condition.apply(this,[t].concat(r))}}]),a}(c.AbstractConditionBlock),c.OrderByBlock=function(i){function a(e){r(this,a);var n=t(this,Object.getPrototypeOf(a).call(this,e));return n._orders=[],n}return e(a,i),v(a,[{key:"order",value:function(t,e){t=this._sanitizeField(t),"string"!=typeof e&&(void 0===e?e="ASC":null!==e&&(e=e?"ASC":"DESC"));for(var r=arguments.length,n=Array(r>2?r-2:0),i=2;r>i;i++)n[i-2]=arguments[i];this._orders.push({field:t,dir:e,values:n||[]})}},{key:"_toParamString",value:function(){var t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],e="",r=[],i=!0,a=!1,l=void 0;try{for(var u,s=this._orders[Symbol.iterator]();!(i=(u=s.next()).done);i=!0){var f=u.value,c=f.field,h=f.dir,v=f.values;e=n(e,", ");var d=this._buildString(c,v,{buildParameterized:t.buildParameterized});e+=d.text,o(d.values)&&d.values.forEach(function(t){return r.push(t)}),null!==h&&(e+=" "+h)}}catch(y){a=!0,l=y}finally{try{!i&&s["return"]&&s["return"]()}finally{if(a)throw l}}return{text:e.length?"ORDER BY "+e:"",values:r}}}]),a}(c.Block),c.JoinBlock=function(i){function a(e){r(this,a);var n=t(this,Object.getPrototypeOf(a).call(this,e));return n._joins=[],n}return e(a,i),v(a,[{key:"join",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?null:arguments[1],r=arguments.length<=2||void 0===arguments[2]?null:arguments[2],n=arguments.length<=3||void 0===arguments[3]?"INNER":arguments[3];t=this._sanitizeTable(t,!0),e=e?this._sanitizeTableAlias(e):e,r=r?this._sanitizeExpression(r):r,this._joins.push({type:n,table:t,alias:e,condition:r})}},{key:"left_join",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?null:arguments[1],r=arguments.length<=2||void 0===arguments[2]?null:arguments[2];this.join(t,e,r,"LEFT")}},{key:"right_join",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?null:arguments[1],r=arguments.length<=2||void 0===arguments[2]?null:arguments[2];this.join(t,e,r,"RIGHT")}},{key:"outer_join",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?null:arguments[1],r=arguments.length<=2||void 0===arguments[2]?null:arguments[2];this.join(t,e,r,"OUTER")}},{key:"left_outer_join",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?null:arguments[1],r=arguments.length<=2||void 0===arguments[2]?null:arguments[2];this.join(t,e,r,"LEFT OUTER")}},{key:"full_join",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?null:arguments[1],r=arguments.length<=2||void 0===arguments[2]?null:arguments[2];this.join(t,e,r,"FULL")}},{key:"cross_join",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?null:arguments[1],r=arguments.length<=2||void 0===arguments[2]?null:arguments[2];this.join(t,e,r,"CROSS")}},{key:"_toParamString",value:function(){var t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],e="",r=[],i=!0,a=!1,o=void 0;try{for(var l,u=this._joins[Symbol.iterator]();!(i=(l=u.next()).done);i=!0){var s=l.value,f=s.type,h=s.table,v=s.alias,d=s.condition;e=n(e,this.options.separator);var y=void 0;if(c.isSquelBuilder(h)){var p=h._toParamString({buildParameterized:t.buildParameterized,nested:!0});p.values.forEach(function(t){return r.push(t)}),y=p.text}else y=this._formatTableName(h);if(e+=f+" JOIN "+y,v&&(e+=" "+this._formatTableAlias(v)),d){e+=" ON ";var g=void 0;g=c.isSquelBuilder(d)?d._toParamString({buildParameterized:t.buildParameterized}):this._buildString(d,[],{buildParameterized:t.buildParameterized}),e+=this._applyNestingFormatting(g.text),g.values.forEach(function(t){return r.push(t)})}}}catch(b){a=!0,o=b}finally{try{!i&&u["return"]&&u["return"]()}finally{if(a)throw o}}return{text:e,values:r}}}]),a}(c.Block),c.UnionBlock=function(i){function a(e){r(this,a);var n=t(this,Object.getPrototypeOf(a).call(this,e));return n._unions=[],n}return e(a,i),v(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 t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],e="",r=[],i=!0,a=!1,o=void 0;try{for(var l,u=this._unions[Symbol.iterator]();!(i=(l=u.next()).done);i=!0){var s=l.value,f=s.type,h=s.table;e=n(e,this.options.separator);var v=void 0;if(h instanceof c.BaseBuilder){var d=h._toParamString({buildParameterized:t.buildParameterized,nested:!0});v=d.text,d.values.forEach(function(t){return r.push(t)})}else e=this._formatTableName(h);e+=f+" "+v}}catch(y){a=!0,o=y}finally{try{!i&&u["return"]&&u["return"]()}finally{if(a)throw o}}return{text:e,values:r}}}]),a}(c.Block),c.QueryBuilder=function(n){function a(e,n){r(this,a);var i=t(this,Object.getPrototypeOf(a).call(this,e));i.blocks=n||[];var o=!0,l=!1,u=void 0;try{for(var s,f=i.blocks[Symbol.iterator]();!(o=(s=f.next()).done);o=!0){var c=s.value,h=c.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,r){i[e]=function(){for(var e=arguments.length,n=Array(e),a=0;e>a;a++)n[a]=arguments[a];return r.call.apply(r,[t].concat(n)),i}}(c,v,d)}}}catch(y){l=!0,u=y}finally{try{!o&&f["return"]&&f["return"]()}finally{if(l)throw u}}return i}return e(a,n),v(a,[{key:"registerValueHandler",value:function(t,e){var r=!0,n=!1,i=void 0;try{for(var o,l=this.blocks[Symbol.iterator]();!(r=(o=l.next()).done);r=!0){var u=o.value;u.registerValueHandler(t,e)}}catch(s){n=!0,i=s}finally{try{!r&&l["return"]&&l["return"]()}finally{if(n)throw i}}return h(Object.getPrototypeOf(a.prototype),"registerValueHandler",this).call(this,t,e),this}},{key:"updateOptions",value:function(t){this.options=i({},this.options,t);var e=!0,r=!1,n=void 0;try{for(var a,o=this.blocks[Symbol.iterator]();!(e=(a=o.next()).done);e=!0){var l=a.value;l.options=i({},l.options,t)}}catch(u){r=!0,n=u}finally{try{!e&&o["return"]&&o["return"]()}finally{if(r)throw n}}}},{key:"_toParamString",value:function(){var t=this,e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];e=i({},this.options,e);var r=this.blocks.map(function(r){return r._toParamString({buildParameterized:e.buildParameterized,queryBuilder:t})}),n=r.map(function(t){return t.text}),a=r.map(function(t){return t.values}),o=n.filter(function(t){return 0<t.length}).join(e.separator),l=[];return a.forEach(function(t){return t.forEach(function(t){return l.push(t)})}),e.nested||e.numberedParameters&&!function(){var t=void 0!==e.numberedParametersStartAt?e.numberedParametersStartAt:1,r=e.parameterCharacter.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&");o=o.replace(new RegExp(r,"g"),function(){return""+e.numberedParametersPrefix+t++})}(),{text:this._applyNestingFormatting(o,!!e.nested),values:l}}},{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}(c.BaseBuilder),c.Select=function(n){function i(e){var n=arguments.length<=1||void 0===arguments[1]?null:arguments[1];return r(this,i),n=n||[new c.StringBlock(e,"SELECT"),new c.FunctionBlock(e),new c.DistinctBlock(e),new c.GetFieldBlock(e),new c.FromTableBlock(e),new c.JoinBlock(e),new c.WhereBlock(e),new c.GroupByBlock(e),new c.HavingBlock(e),new c.OrderByBlock(e),new c.LimitBlock(e),new c.OffsetBlock(e),new c.UnionBlock(e)],
t(this,Object.getPrototypeOf(i).call(this,e,n))}return e(i,n),i}(c.QueryBuilder),c.Update=function(n){function i(e){var n=arguments.length<=1||void 0===arguments[1]?null:arguments[1];return r(this,i),n=n||[new c.StringBlock(e,"UPDATE"),new c.UpdateTableBlock(e),new c.SetFieldBlock(e),new c.WhereBlock(e),new c.OrderByBlock(e),new c.LimitBlock(e)],t(this,Object.getPrototypeOf(i).call(this,e,n))}return e(i,n),i}(c.QueryBuilder),c.Delete=function(n){function a(e){var n=arguments.length<=1||void 0===arguments[1]?null:arguments[1];return r(this,a),n=n||[new c.StringBlock(e,"DELETE"),new c.TargetTableBlock(e),new c.FromTableBlock(i({},e,{singleTable:!0})),new c.JoinBlock(e),new c.WhereBlock(e),new c.OrderByBlock(e),new c.LimitBlock(e)],t(this,Object.getPrototypeOf(a).call(this,e,n))}return e(a,n),a}(c.QueryBuilder),c.Insert=function(n){function i(e){var n=arguments.length<=1||void 0===arguments[1]?null:arguments[1];return r(this,i),n=n||[new c.StringBlock(e,"INSERT"),new c.IntoTableBlock(e),new c.InsertFieldValueBlock(e),new c.InsertFieldsFromQueryBlock(e)],t(this,Object.getPrototypeOf(i).call(this,e,n))}return e(i,n),i}(c.QueryBuilder);var p={VERSION:"5.11.1",flavour:f,expr:function(t){return new c.Expression(t)},"case":function(t,e){return new c.Case(t,e)},select:function(t,e){return new c.Select(t,e)},update:function(t,e){return new c.Update(t,e)},insert:function(t,e){return new c.Insert(t,e)},"delete":function(t,e){return new c.Delete(t,e)},str:function(){var t=new c.FunctionBlock;return t["function"].apply(t,arguments),t},rstr:function(){var t=new c.FunctionBlock({rawNesting:!0});return t["function"].apply(t,arguments),t},registerValueHandler:c.registerValueHandler};return p.remove=p["delete"],p.cls=c,p}var h=function p(t,e,r){null===t&&(t=Function.prototype);var n=Object.getOwnPropertyDescriptor(t,e);if(void 0===n){var i=Object.getPrototypeOf(t);return null===i?void 0:p(i,e,r)}if("value"in n)return n.value;var a=n.get;if(void 0!==a)return a.call(r)},v=function(){function t(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,r,n){return r&&t(e.prototype,r),n&&t(e,n),e}}(),d="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},y=c();return y.flavours={},y.useFlavour=function(){var t=arguments.length<=0||void 0===arguments[0]?null:arguments[0];if(!t)return y;if(y.flavours[t]instanceof Function){var e=c(t);return y.flavours[t].call(null,e),e.flavours=y.flavours,e.useFlavour=y.useFlavour,e}throw new Error("Flavour not available: "+t)},y});
/*! 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,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 e(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 n(t,e){return t.length?t+e:t}function i(t){for(var e=arguments.length,r=Array(e>1?e-1:0),n=1;n<e;n++)r[n-1]=arguments[n];if(t&&r){var i=!0,o=!1,a=void 0;try{for(var l,u=function(){var e=l.value;"object"===("undefined"==typeof e?"undefined":d(e))&&Object.getOwnPropertyNames(e).forEach(function(r){t[r]=e[r]})},s=r[Symbol.iterator]();!(i=(l=s.next()).done);i=!0)u()}catch(f){o=!0,a=f}finally{try{!i&&s["return"]&&s["return"]()}finally{if(o)throw a}}}return t}function o(t){return t&&t.constructor.prototype===Object.prototype}function a(t){return t&&t.constructor.prototype===Array.prototype}function l(t){if(!t)return t;if("function"==typeof t.clone)return t.clone();if(o(t)||a(t)){var e=new t.constructor;return Object.getOwnPropertyNames(t).forEach(function(r){"function"!=typeof t[r]&&(e[r]=l(t[r]))}),e}return JSON.parse(JSON.stringify(t))}function u(t,e,r){var n="undefined"==typeof e?"undefined":d(e);if("function"!==n&&"string"!==n)throw new Error("type must be a class constructor or string");if("function"!=typeof r)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=r)}}catch(f){o=!0,a=f}finally{try{!i&&u["return"]&&u["return"]()}finally{if(o)throw a}}t.push({type:e,handler:r})}function s(t,e,r){return f(t,e)||f(t,r)}function f(t,e){for(var r=0;r<e.length;r++){var n=e[r];if(("undefined"==typeof t?"undefined":d(t))===n.type||"string"!=typeof n.type&&t instanceof n.type)return n.handler}}function c(){var f=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,c={isSquelBuilder:function(t){return t&&!!t._toParamString}},_=function(t){return!c.isSquelBuilder(t)||!t.options.rawNesting};c.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,rawNesting:!1},c.globalValueHandlers=[],c.registerValueHandler=function(t,e){u(c.globalValueHandlers,t,e)},c.Cloneable=function(){function t(){r(this,t)}return v(t,[{key:"clone",value:function(){var t=new this.constructor;return i(t,l(i({},this)))}}]),t}(),c.BaseBuilder=function(n){function o(e){r(this,o);var n=t(this,(o.__proto__||Object.getPrototypeOf(o)).call(this)),a=JSON.parse(JSON.stringify(c.DefaultQueryBuilderOptions));return["stringFormatter"].forEach(function(t){a[t]=c.DefaultQueryBuilderOptions[t]}),n.options=i({},a,e),n}return e(o,n),v(o,[{key:"registerValueHandler",value:function(t,e){return u(this.options.valueHandlers,t,e),this}},{key:"_sanitizeExpression",value:function(t){if(!c.isSquelBuilder(t)&&"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 c.isSquelBuilder(t)||(t=this._sanitizeName(t,"field name")),t}},{key:"_sanitizeBaseBuilder",value:function(t){if(c.isSquelBuilder(t))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":d(t);if(null===t);else if("string"===e||"number"===e||"boolean"===e);else if(c.isSquelBuilder(t));else{var r=!!s(t,this.options.valueHandlers,c.globalValueHandlers);if(!r)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=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(this.options.autoQuoteFieldNames){var r=this.options.nameQuoteCharacter;t=e.ignorePeriodsForFieldNameQuotes?""+r+t+r:t.split(".").map(function(t){return"*"===t?t:""+r+t+r}).join(".")}return t}},{key:"_formatCustomValue",value:function(t,e,r){var n=s(t,this.options.valueHandlers,c.globalValueHandlers);return n&&(t=n(t,e,r),t&&t.rawNesting)?{formatted:!0,rawNesting:!0,value:t.value}:{formatted:!!n,value:t}}},{key:"_formatValueForParamArray",value:function(t){var e=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return a(t)?t.map(function(t){return e._formatValueForParamArray(t,r)}):this._formatCustomValue(t,!0,r).value}},{key:"_formatValueForQueryString",value:function(t){var e=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=this._formatCustomValue(t,!1,r),i=n.rawNesting,o=n.formatted,l=n.value;if(o)return i?l:this._applyNestingFormatting(l,_(t));if(a(l))l=l.map(function(t){return e._formatValueForQueryString(t)}),l=this._applyNestingFormatting(l.join(", "),_(l));else{var u="undefined"==typeof l?"undefined":d(l);if(null===l)l="NULL";else if("boolean"===u)l=l?"TRUE":"FALSE";else if(c.isSquelBuilder(l))l=this._applyNestingFormatting(l.toString(),_(l));else if("number"!==u){if("string"===u&&this.options.stringFormatter)return this.options.stringFormatter(l);if(r.dontQuote)l=""+l;else{var s=this._escapeValue(l);l="'"+s+"'"}}}return l}},{key:"_applyNestingFormatting",value:function(t){var e=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];if(t&&"string"==typeof t&&e&&!this.options.rawNesting){var r="("===t.charAt(0)&&")"===t.charAt(t.length-1);if(r)for(var n=0,i=1;t.length-1>++n;){var o=t.charAt(n);if("("===o)i++;else if(")"===o&&(i--,1>i)){r=!1;break}}r||(t="("+t+")")}return t}},{key:"_buildString",value:function(t,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},n=r.nested,i=r.buildParameterized,o=r.formattingOptions;e=e||[],t=t||"";for(var l="",u=-1,s=[],f=this.options.parameterCharacter,h=0;t.length>h;)if(t.substr(h,f.length)===f){var v=e[++u];if(i)if(c.isSquelBuilder(v)){var d=v._toParamString({buildParameterized:i,nested:!0});l+=d.text,d.values.forEach(function(t){return s.push(t)})}else if(v=this._formatValueForParamArray(v,o),a(v)){var _=v.map(function(){return f}).join(", ");l+="("+_+")",v.forEach(function(t){return s.push(t)})}else l+=f,s.push(v);else l+=this._formatValueForQueryString(v,o);h+=f.length}else l+=t.charAt(h),h++;return{text:this._applyNestingFormatting(l,!!n),values:s}}},{key:"_buildManyStrings",value:function(t,e){for(var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},n=[],i=[],o=0;t.length>o;++o){var a=t[o],l=e[o],u=this._buildString(a,l,{buildParameterized:r.buildParameterized,nested:!1}),s=u.text,f=u.values;n.push(s),f.forEach(function(t){return i.push(t)})}return n=n.join(this.options.separator),{text:n.length?this._applyNestingFormatting(n,!!r.nested):"",values:i}}},{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(i({},t,{buildParameterized:!0}))}}]),o}(c.Cloneable),c.Expression=function(n){function i(e){r(this,i);var n=t(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,e));return n._nodes=[],n}return e(i,n),v(i,[{key:"and",value:function(t){for(var e=arguments.length,r=Array(e>1?e-1:0),n=1;n<e;n++)r[n-1]=arguments[n];return t=this._sanitizeExpression(t),this._nodes.push({type:"AND",expr:t,para:r}),this}},{key:"or",value:function(t){for(var e=arguments.length,r=Array(e>1?e-1:0),n=1;n<e;n++)r[n-1]=arguments[n];return t=this._sanitizeExpression(t),this._nodes.push({type:"OR",expr:t,para:r}),this}},{key:"_toParamString",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=[],r=[],n=!0,i=!1,o=void 0;try{for(var a,l=this._nodes[Symbol.iterator]();!(n=(a=l.next()).done);n=!0){var u=a.value,s=u.type,f=u.expr,h=u.para,v=c.isSquelBuilder(f)?f._toParamString({buildParameterized:t.buildParameterized,nested:!0}):this._buildString(f,h,{buildParameterized:t.buildParameterized}),d=v.text,_=v.values;e.length&&e.push(s),e.push(d),_.forEach(function(t){return r.push(t)})}}catch(p){i=!0,o=p}finally{try{!n&&l["return"]&&l["return"]()}finally{if(i)throw o}}return e=e.join(" "),{text:this._applyNestingFormatting(e,!!t.nested),values:r}}}]),i}(c.BaseBuilder),c.Case=function(a){function l(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};r(this,l);var a=t(this,(l.__proto__||Object.getPrototypeOf(l)).call(this,n));return o(e)&&(n=e,e=null),e&&(a._fieldName=a._sanitizeField(e)),a.options=i({},c.DefaultQueryBuilderOptions,n),a._cases=[],a._elseValue=null,a}return e(l,a),v(l,[{key:"when",value:function(t){for(var e=arguments.length,r=Array(e>1?e-1:0),n=1;n<e;n++)r[n-1]=arguments[n];return this._cases.unshift({expression:t,values:r||[]}),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 t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e="",r=[],i=!0,o=!1,a=void 0;try{for(var l,u=this._cases[Symbol.iterator]();!(i=(l=u.next()).done);i=!0){var s=l.value,f=s.expression,c=s.values,h=s.result;e=n(e," ");var v=this._buildString(f,c,{buildParameterized:t.buildParameterized,nested:!0});e+="WHEN "+v.text+" THEN "+this._formatValueForQueryString(h),v.values.forEach(function(t){return r.push(t)})}}catch(d){o=!0,a=d}finally{try{!i&&u["return"]&&u["return"]()}finally{if(o)throw a}}return e.length?(e+=" ELSE "+this._formatValueForQueryString(this._elseValue)+" END",this._fieldName&&(e=this._fieldName+" "+e),e="CASE "+e):e=this._formatValueForQueryString(this._elseValue),{text:e,values:r}}}]),l}(c.BaseBuilder),c.Block=function(n){function i(e){return r(this,i),t(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,e))}return e(i,n),v(i,[{key:"exposedMethods",value:function(){for(var t={},e=this;e;)Object.getOwnPropertyNames(e).forEach(function(r){"constructor"===r||"function"!=typeof e[r]||"_"===r.charAt(0)||c.Block.prototype[r]||(t[r]=e[r])}),e=Object.getPrototypeOf(e);return t}}]),i}(c.BaseBuilder),c.StringBlock=function(n){function i(e,n){r(this,i);var o=t(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,e));return o._str=n,o}return e(i,n),v(i,[{key:"_toParamString",value:function(){arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return{text:this._str,values:[]}}}]),i}(c.Block),c.FunctionBlock=function(n){function i(e){r(this,i);var n=t(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,e));return n._strings=[],n._values=[],n}return e(i,n),v(i,[{key:"function",value:function(t){this._strings.push(t);for(var e=arguments.length,r=Array(e>1?e-1:0),n=1;n<e;n++)r[n-1]=arguments[n];this._values.push(r)}},{key:"_toParamString",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return this._buildManyStrings(this._strings,this._values,t)}}]),i}(c.Block),c.registerValueHandler(c.FunctionBlock,function(t){var e=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return e?t.toParam():t.toString()}),c.AbstractTableBlock=function(i){function o(e,n){r(this,o);var i=t(this,(o.__proto__||Object.getPrototypeOf(o)).call(this,e));return i._tables=[],i}return e(o,i),v(o,[{key:"_table",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;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 t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e="",r=[];if(this._hasTable()){var 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,f=s.table,h=s.alias;e=n(e,", ");var v=void 0;if(c.isSquelBuilder(f)){var d=f._toParamString({buildParameterized:t.buildParameterized,nested:!0}),_=d.text,p=d.values;v=_,p.forEach(function(t){return r.push(t)})}else v=this._formatTableName(f);h&&(v+=" "+this._formatTableAlias(h)),e+=v}}catch(y){o=!0,a=y}finally{try{!i&&u["return"]&&u["return"]()}finally{if(o)throw a}}this.options.prefix&&(e=this.options.prefix+" "+e)}return{text:e,values:r}}}]),o}(c.Block),c.TargetTableBlock=function(n){function i(){return r(this,i),t(this,(i.__proto__||Object.getPrototypeOf(i)).apply(this,arguments))}return e(i,n),v(i,[{key:"target",value:function(t){this._table(t)}}]),i}(c.AbstractTableBlock),c.UpdateTableBlock=function(n){function i(){return r(this,i),t(this,(i.__proto__||Object.getPrototypeOf(i)).apply(this,arguments))}return e(i,n),v(i,[{key:"table",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;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 h(i.prototype.__proto__||Object.getPrototypeOf(i.prototype),"_toParamString",this).call(this,t)}}]),i}(c.AbstractTableBlock),c.FromTableBlock=function(n){function o(e){return r(this,o),t(this,(o.__proto__||Object.getPrototypeOf(o)).call(this,i({},e,{prefix:"FROM"})))}return e(o,n),v(o,[{key:"from",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;this._table(t,e)}}]),o}(c.AbstractTableBlock),c.IntoTableBlock=function(n){function o(e){return r(this,o),t(this,(o.__proto__||Object.getPrototypeOf(o)).call(this,i({},e,{prefix:"INTO",singleTable:!0})))}return e(o,n),v(o,[{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 h(o.prototype.__proto__||Object.getPrototypeOf(o.prototype),"_toParamString",this).call(this,t)}}]),o}(c.AbstractTableBlock),c.GetFieldBlock=function(i){function o(e){r(this,o);var n=t(this,(o.__proto__||Object.getPrototypeOf(o)).call(this,e));return n._fields=[],n}return e(o,i),v(o,[{key:"fields",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(a(t)){var r=!0,n=!1,i=void 0;try{for(var o,l=t[Symbol.iterator]();!(r=(o=l.next()).done);r=!0){var u=o.value;this.field(u,null,e)}}catch(s){n=!0,i=s}finally{try{!r&&l["return"]&&l["return"]()}finally{if(n)throw i}}}else for(var f in t){var c=t[f];this.field(f,c,e)}}},{key:"field",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};e=e?this._sanitizeFieldAlias(e):e,t=this._sanitizeField(t);var n=this._fields.filter(function(r){return r.name===t&&r.alias===e});return n.length?this:void this._fields.push({name:t,alias:e,options:r})}},{key:"_toParamString",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=t.queryBuilder,r=t.buildParameterized,i="",o=[],a=!0,l=!1,u=void 0;try{for(var s,f=this._fields[Symbol.iterator]();!(a=(s=f.next()).done);a=!0){var h=s.value;i=n(i,", ");var v=h.name,d=h.alias,_=h.options;if("string"==typeof v)i+=this._formatFieldName(v,_);else{var p=v._toParamString({nested:!0,buildParameterized:r});i+=p.text,p.values.forEach(function(t){return o.push(t)})}d&&(i+=" AS "+this._formatFieldAlias(d))}}catch(y){l=!0,u=y}finally{try{!a&&f["return"]&&f["return"]()}finally{if(l)throw u}}if(!i.length){var g=e&&e.getBlock(c.FromTableBlock);g&&g._hasTable()&&(i="*")}return{text:i,values:o}}}]),o}(c.Block),c.AbstractSetFieldBlock=function(n){function i(e){r(this,i);var n=t(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,e));return n._reset(),n}return e(i,n),v(i,[{key:"_reset",value:function(){this._fields=[],this._values=[[]],this._valueOptions=[[]]}},{key:"_set",value:function(t,e){var r=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 n=this._fields.indexOf(t);-1===n&&(this._fields.push(t),n=this._fields.length-1),this._values[0][n]=e,this._valueOptions[0][n]=r}},{key:"_setFields",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if("object"!==("undefined"==typeof t?"undefined":d(t)))throw new Error("Expected an object but got "+("undefined"==typeof t?"undefined":d(t)));for(var r in t)this._set(r,t[r],e)}},{key:"_setFieldsRows",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!a(t))throw new Error("Expected an array of objects but got "+("undefined"==typeof t?"undefined":d(t)));this._reset();for(var r=0;t.length>r;++r){var n=t[r];for(var i in n){var o=n[i];i=this._sanitizeField(i),o=this._sanitizeValue(o);var l=this._fields.indexOf(i);if(0<r&&-1===l)throw new Error("All fields in subsequent rows must match the fields in the first row");-1===l&&(this._fields.push(i),l=this._fields.length-1),a(this._values[r])||(this._values[r]=[],this._valueOptions[r]=[]),this._values[r][l]=o,this._valueOptions[r][l]=e}}}}]),i}(c.Block),c.SetFieldBlock=function(i){function o(){return r(this,o),t(this,(o.__proto__||Object.getPrototypeOf(o)).apply(this,arguments))}return e(o,i),v(o,[{key:"set",value:function(t,e,r){this._set(t,e,r)}},{key:"setFields",value:function(t,e){this._setFields(t,e)}},{key:"_toParamString",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=t.buildParameterized;if(0>=this._fields.length)throw new Error("set() needs to be called");for(var r="",i=[],o=0;o<this._fields.length;++o){r=n(r,", ");var a=this._formatFieldName(this._fields[o]),l=this._values[0][o];0>a.indexOf("=")&&(a=a+" = "+this.options.parameterCharacter);var u=this._buildString(a,[l],{buildParameterized:e,formattingOptions:this._valueOptions[0][o]});r+=u.text,u.values.forEach(function(t){return i.push(t)})}return{text:"SET "+r,values:i}}}]),o}(c.AbstractSetFieldBlock),c.InsertFieldValueBlock=function(i){function o(){return r(this,o),t(this,(o.__proto__||Object.getPrototypeOf(o)).apply(this,arguments))}return e(o,i),v(o,[{key:"set",value:function(t,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};this._set(t,e,r)}},{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 t=this,e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.buildParameterized,i=this._fields.map(function(e){return t._formatFieldName(e)}).join(", "),o=[],a=[],l=0;l<this._values.length;++l){o[l]="";for(var u=0;u<this._values[l].length;++u){var s=this._buildString(this.options.parameterCharacter,[this._values[l][u]],{buildParameterized:r,formattingOptions:this._valueOptions[l][u]});s.values.forEach(function(t){return a.push(t)}),o[l]=n(o[l],", "),o[l]+=s.text}}return{text:i.length?"("+i+") VALUES ("+o.join("), (")+")":"",values:a}}}]),o}(c.AbstractSetFieldBlock),c.InsertFieldsFromQueryBlock=function(n){function i(e){r(this,i);var n=t(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,e));return n._fields=[],n._query=null,n}return e(i,n),v(i,[{key:"fromQuery",value:function(t,e){var r=this;this._fields=t.map(function(t){return r._sanitizeField(t)}),this._query=this._sanitizeBaseBuilder(e)}},{key:"_toParamString",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e="",r=[];if(this._fields.length&&this._query){var n=this._query._toParamString({buildParameterized:t.buildParameterized,nested:!0}),i=n.text,o=n.values;e="("+this._fields.join(", ")+") "+this._applyNestingFormatting(i),r=o}return{text:e,values:r}}}]),i}(c.Block),c.DistinctBlock=function(n){function i(){return r(this,i),t(this,(i.__proto__||Object.getPrototypeOf(i)).apply(this,arguments))}return e(i,n),v(i,[{key:"distinct",value:function(){this._useDistinct=!0}},{key:"_toParamString",value:function(){return{text:this._useDistinct?"DISTINCT":"",values:[]}}}]),i}(c.Block),c.GroupByBlock=function(n){function i(e){r(this,i);var n=t(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,e));return n._groups=[],n}return e(i,n),v(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}(c.Block),c.AbstractVerbSingleValueBlock=function(n){function i(e){r(this,i);var n=t(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,e));return n._value=null,n}return e(i,n),v(i,[{key:"_setValue",value:function(t){this._value=null!==t?this._sanitizeLimitOffset(t):t}},{key:"_toParamString",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=null!==this._value?this.options.verb+" "+this.options.parameterCharacter:"",r=null!==this._value?[this._value]:[];return this._buildString(e,r,t)}}]),i}(c.Block),c.OffsetBlock=function(n){function o(e){return r(this,o),t(this,(o.__proto__||Object.getPrototypeOf(o)).call(this,i({},e,{verb:"OFFSET"})))}return e(o,n),v(o,[{key:"offset",value:function(t){this._setValue(t)}}]),o}(c.AbstractVerbSingleValueBlock),c.LimitBlock=function(n){function o(e){return r(this,o),t(this,(o.__proto__||Object.getPrototypeOf(o)).call(this,i({},e,{verb:"LIMIT"})))}return e(o,n),v(o,[{key:"limit",value:function(t){this._setValue(t)}}]),o}(c.AbstractVerbSingleValueBlock),c.AbstractConditionBlock=function(n){function i(e){r(this,i);var n=t(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,e));return n._conditions=[],n}return e(i,n),v(i,[{key:"_condition",value:function(t){t=this._sanitizeExpression(t);for(var e=arguments.length,r=Array(e>1?e-1:0),n=1;n<e;n++)r[n-1]=arguments[n];this._conditions.push({expr:t,values:r||[]})}},{key:"_toParamString",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=[],r=[],n=!0,i=!1,o=void 0;try{for(var a,l=this._conditions[Symbol.iterator]();!(n=(a=l.next()).done);n=!0){var u=a.value,s=u.expr,f=u.values,h=c.isSquelBuilder(s)?s._toParamString({buildParameterized:t.buildParameterized}):this._buildString(s,f,{buildParameterized:t.buildParameterized});h.text.length&&e.push(h.text),h.values.forEach(function(t){return r.push(t)})}}catch(v){i=!0,o=v}finally{try{!n&&l["return"]&&l["return"]()}finally{if(i)throw o}}return e.length&&(e=e.join(") AND (")),{text:e.length?this.options.verb+" ("+e+")":"",values:r}}}]),i}(c.Block),c.WhereBlock=function(n){function o(e){return r(this,o),t(this,(o.__proto__||Object.getPrototypeOf(o)).call(this,i({},e,{verb:"WHERE"})))}return e(o,n),v(o,[{key:"where",value:function(t){for(var e=arguments.length,r=Array(e>1?e-1:0),n=1;n<e;n++)r[n-1]=arguments[n];this._condition.apply(this,[t].concat(r))}}]),o}(c.AbstractConditionBlock),c.HavingBlock=function(n){function o(e){return r(this,o),t(this,(o.__proto__||Object.getPrototypeOf(o)).call(this,i({},e,{verb:"HAVING"})))}return e(o,n),v(o,[{key:"having",value:function(t){for(var e=arguments.length,r=Array(e>1?e-1:0),n=1;n<e;n++)r[n-1]=arguments[n];this._condition.apply(this,[t].concat(r))}}]),o}(c.AbstractConditionBlock),c.OrderByBlock=function(i){function o(e){r(this,o);var n=t(this,(o.__proto__||Object.getPrototypeOf(o)).call(this,e));return n._orders=[],n}return e(o,i),v(o,[{key:"order",value:function(t,e){t=this._sanitizeField(t),"string"!=typeof e&&(void 0===e?e="ASC":null!==e&&(e=e?"ASC":"DESC"));for(var r=arguments.length,n=Array(r>2?r-2:0),i=2;i<r;i++)n[i-2]=arguments[i];this._orders.push({field:t,dir:e,values:n||[]})}},{key:"_toParamString",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e="",r=[],i=!0,o=!1,l=void 0;try{for(var u,s=this._orders[Symbol.iterator]();!(i=(u=s.next()).done);i=!0){var f=u.value,c=f.field,h=f.dir,v=f.values;e=n(e,", ");var d=this._buildString(c,v,{buildParameterized:t.buildParameterized});e+=d.text,a(d.values)&&d.values.forEach(function(t){return r.push(t)}),null!==h&&(e+=" "+h)}}catch(_){o=!0,l=_}finally{try{!i&&s["return"]&&s["return"]()}finally{if(o)throw l}}return{text:e.length?"ORDER BY "+e:"",values:r}}}]),o}(c.Block),c.JoinBlock=function(i){function o(e){r(this,o);var n=t(this,(o.__proto__||Object.getPrototypeOf(o)).call(this,e));return n._joins=[],n}return e(o,i),v(o,[{key:"join",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"INNER";t=this._sanitizeTable(t,!0),e=e?this._sanitizeTableAlias(e):e,r=r?this._sanitizeExpression(r):r,this._joins.push({type:n,table:t,alias:e,condition:r})}},{key:"left_join",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;this.join(t,e,r,"LEFT")}},{key:"right_join",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;this.join(t,e,r,"RIGHT")}},{key:"outer_join",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;this.join(t,e,r,"OUTER")}},{key:"left_outer_join",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;this.join(t,e,r,"LEFT OUTER")}},{key:"full_join",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;this.join(t,e,r,"FULL")}},{key:"cross_join",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;this.join(t,e,r,"CROSS")}},{key:"_toParamString",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e="",r=[],i=!0,o=!1,a=void 0;try{for(var l,u=this._joins[Symbol.iterator]();!(i=(l=u.next()).done);i=!0){var s=l.value,f=s.type,h=s.table,v=s.alias,d=s.condition;e=n(e,this.options.separator);var _=void 0;if(c.isSquelBuilder(h)){var p=h._toParamString({buildParameterized:t.buildParameterized,nested:!0});p.values.forEach(function(t){return r.push(t)}),_=p.text}else _=this._formatTableName(h);if(e+=f+" JOIN "+_,v&&(e+=" "+this._formatTableAlias(v)),d){e+=" ON ";var y=void 0;y=c.isSquelBuilder(d)?d._toParamString({buildParameterized:t.buildParameterized}):this._buildString(d,[],{buildParameterized:t.buildParameterized}),e+=this._applyNestingFormatting(y.text),y.values.forEach(function(t){return r.push(t)})}}}catch(g){o=!0,a=g}finally{try{!i&&u["return"]&&u["return"]()}finally{if(o)throw a}}return{text:e,values:r}}}]),o}(c.Block),c.UnionBlock=function(i){function o(e){r(this,o);var n=t(this,(o.__proto__||Object.getPrototypeOf(o)).call(this,e));return n._unions=[],n}return e(o,i),v(o,[{key:"union",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"UNION";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 t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e="",r=[],i=!0,o=!1,a=void 0;try{for(var l,u=this._unions[Symbol.iterator]();!(i=(l=u.next()).done);i=!0){var s=l.value,f=s.type,h=s.table;e=n(e,this.options.separator);var v=void 0;if(h instanceof c.BaseBuilder){var d=h._toParamString({buildParameterized:t.buildParameterized,nested:!0});v=d.text,d.values.forEach(function(t){return r.push(t)})}else e=this._formatTableName(h);e+=f+" "+v}}catch(_){o=!0,a=_}finally{try{!i&&u["return"]&&u["return"]()}finally{if(o)throw a}}return{text:e,values:r}}}]),o}(c.Block),c.QueryBuilder=function(n){function o(e,n){r(this,o);var i=t(this,(o.__proto__||Object.getPrototypeOf(o)).call(this,e));i.blocks=n||[];var a=!0,l=!1,u=void 0;try{for(var s,f=i.blocks[Symbol.iterator]();!(a=(s=f.next()).done);a=!0){var c=s.value,h=c.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,r){i[e]=function(){for(var e=arguments.length,n=Array(e),o=0;o<e;o++)n[o]=arguments[o];return r.call.apply(r,[t].concat(n)),i}}(c,v,d)}}}catch(_){l=!0,u=_}finally{try{!a&&f["return"]&&f["return"]()}finally{if(l)throw u}}return i}return e(o,n),v(o,[{key:"registerValueHandler",value:function(t,e){var r=!0,n=!1,i=void 0;try{for(var a,l=this.blocks[Symbol.iterator]();!(r=(a=l.next()).done);r=!0){var u=a.value;u.registerValueHandler(t,e)}}catch(s){n=!0,i=s}finally{try{!r&&l["return"]&&l["return"]()}finally{if(n)throw i}}return h(o.prototype.__proto__||Object.getPrototypeOf(o.prototype),"registerValueHandler",this).call(this,t,e),this}},{key:"updateOptions",value:function(t){this.options=i({},this.options,t);var e=!0,r=!1,n=void 0;try{for(var o,a=this.blocks[Symbol.iterator]();!(e=(o=a.next()).done);e=!0){var l=o.value;l.options=i({},l.options,t)}}catch(u){r=!0,n=u}finally{try{!e&&a["return"]&&a["return"]()}finally{if(r)throw n}}}},{key:"_toParamString",value:function(){var t=this,e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};e=i({},this.options,e);var r=this.blocks.map(function(r){return r._toParamString({buildParameterized:e.buildParameterized,queryBuilder:t})}),n=r.map(function(t){return t.text}),o=r.map(function(t){return t.values}),a=n.filter(function(t){return 0<t.length}).join(e.separator),l=[];if(o.forEach(function(t){return t.forEach(function(t){return l.push(t)})}),!e.nested&&e.numberedParameters){var u=void 0!==e.numberedParametersStartAt?e.numberedParametersStartAt:1,s=e.parameterCharacter.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&");a=a.replace(new RegExp(s,"g"),function(){return""+e.numberedParametersPrefix+u++})}return{text:this._applyNestingFormatting(a,!!e.nested),values:l}}},{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]}}]),o}(c.BaseBuilder),c.Select=function(n){function i(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;return r(this,i),n=n||[new c.StringBlock(e,"SELECT"),new c.FunctionBlock(e),new c.DistinctBlock(e),new c.GetFieldBlock(e),new c.FromTableBlock(e),new c.JoinBlock(e),new c.WhereBlock(e),new c.GroupByBlock(e),new c.HavingBlock(e),new c.OrderByBlock(e),new c.LimitBlock(e),new c.OffsetBlock(e),new c.UnionBlock(e)],t(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,e,n))}return e(i,n),i}(c.QueryBuilder),c.Update=function(n){function i(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;return r(this,i),n=n||[new c.StringBlock(e,"UPDATE"),new c.UpdateTableBlock(e),new c.SetFieldBlock(e),new c.WhereBlock(e),new c.OrderByBlock(e),new c.LimitBlock(e)],t(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,e,n))}return e(i,n),i}(c.QueryBuilder),c.Delete=function(n){function o(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;return r(this,o),n=n||[new c.StringBlock(e,"DELETE"),new c.TargetTableBlock(e),new c.FromTableBlock(i({},e,{singleTable:!0})),new c.JoinBlock(e),new c.WhereBlock(e),new c.OrderByBlock(e),new c.LimitBlock(e)],t(this,(o.__proto__||Object.getPrototypeOf(o)).call(this,e,n))}return e(o,n),o}(c.QueryBuilder),c.Insert=function(n){function i(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;return r(this,i),n=n||[new c.StringBlock(e,"INSERT"),new c.IntoTableBlock(e),new c.InsertFieldValueBlock(e),new c.InsertFieldsFromQueryBlock(e)],t(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,e,n))}return e(i,n),i}(c.QueryBuilder);var p={VERSION:"5.12.0",flavour:f,expr:function(t){return new c.Expression(t)},"case":function(t,e){return new c.Case(t,e)},select:function(t,e){return new c.Select(t,e)},update:function(t,e){return new c.Update(t,e)},insert:function(t,e){return new c.Insert(t,e)},"delete":function(t,e){return new c.Delete(t,e)},str:function(){var t=new c.FunctionBlock;return t["function"].apply(t,arguments),t},rstr:function(){var t=new c.FunctionBlock({rawNesting:!0});return t["function"].apply(t,arguments),t},registerValueHandler:c.registerValueHandler};return p.remove=p["delete"],p.cls=c,p}var h=function p(t,e,r){null===t&&(t=Function.prototype);var n=Object.getOwnPropertyDescriptor(t,e);if(void 0===n){var i=Object.getPrototypeOf(t);return null===i?void 0:p(i,e,r)}if("value"in n)return n.value;var o=n.get;if(void 0!==o)return o.call(r)},v=function(){function t(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,r,n){return r&&t(e.prototype,r),n&&t(e,n),e}}(),d="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},_=c();return _.flavours={},_.useFlavour=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if(!t)return _;if(_.flavours[t]instanceof Function){var e=c(t);return _.flavours[t].call(null,e),e.flavours=_.flavours,e.useFlavour=_.useFlavour,e}throw new Error("Flavour not available: "+t)},_});

@@ -1,2 +0,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,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 e(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 n(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function r(t,e){return t.length?t+e:t}function i(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,l=void 0;try{for(var a,u=function(){var e=a.value;"object"===("undefined"==typeof e?"undefined":d(e))&&Object.getOwnPropertyNames(e).forEach(function(n){t[n]=e[n]})},s=n[Symbol.iterator]();!(i=(a=s.next()).done);i=!0)u()}catch(c){o=!0,l=c}finally{try{!i&&s["return"]&&s["return"]()}finally{if(o)throw l}}}return t}function o(t){return t&&t.constructor.prototype===Object.prototype}function l(t){return t&&t.constructor.prototype===Array.prototype}function a(t){if(!t)return t;if("function"==typeof t.clone)return t.clone();if(!o(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]=a(t[n]))}),{v:e}}();return"object"===("undefined"==typeof e?"undefined":d(e))?e.v:void 0}function u(t,e,n){var r="undefined"==typeof e?"undefined":d(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,l=void 0;try{for(var a,u=t[Symbol.iterator]();!(i=(a=u.next()).done);i=!0){var s=a.value;if(s.type===e)return void(s.handler=n)}}catch(c){o=!0,l=c}finally{try{!i&&u["return"]&&u["return"]()}finally{if(o)throw l}}t.push({type:e,handler:n})}function s(t,e,n){return c(t,e)||c(t,n)}function c(t,e){for(var n=0;n<e.length;n++){var r=e[n];if(("undefined"==typeof t?"undefined":d(t))===r.type||"string"!=typeof r.type&&t instanceof r.type)return r.handler}}function f(){var c=arguments.length<=0||void 0===arguments[0]?null:arguments[0],f={isSquelBuilder:function(t){return t&&!!t._toParamString}},p=function(t){return!f.isSquelBuilder(t)||!t.options.rawNesting};f.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,rawNesting:!1},f.globalValueHandlers=[],f.registerValueHandler=function(t,e){u(f.globalValueHandlers,t,e)},f.Cloneable=function(){function t(){n(this,t)}return v(t,[{key:"clone",value:function(){var t=new this.constructor;return i(t,a(i({},this)))}}]),t}(),f.BaseBuilder=function(r){function o(e){n(this,o);var r=t(this,Object.getPrototypeOf(o).call(this)),l=JSON.parse(JSON.stringify(f.DefaultQueryBuilderOptions));return["stringFormatter"].forEach(function(t){l[t]=f.DefaultQueryBuilderOptions[t]}),r.options=i({},l,e),r}return e(o,r),v(o,[{key:"registerValueHandler",value:function(t,e){return u(this.options.valueHandlers,t,e),this}},{key:"_sanitizeExpression",value:function(t){if(!f.isSquelBuilder(t)&&"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 f.isSquelBuilder(t)||(t=this._sanitizeName(t,"field name")),t}},{key:"_sanitizeBaseBuilder",value:function(t){if(f.isSquelBuilder(t))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":d(t);if(null===t);else if("string"===e||"number"===e||"boolean"===e);else if(f.isSquelBuilder(t));else{var n=!!s(t,this.options.valueHandlers,f.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,e,n){var r=s(t,this.options.valueHandlers,f.globalValueHandlers);return r&&(t=r(t,e,n),t&&t.rawNesting)?{formatted:!0,rawNesting:!0,value:t.value}:{formatted:!!r,value:t}}},{key:"_formatValueForParamArray",value:function(t){var e=this,n=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];return l(t)?t.map(function(t){return e._formatValueForParamArray(t,n)}):this._formatCustomValue(t,!0,n).value}},{key:"_formatValueForQueryString",value:function(t){var e=this,n=arguments.length<=1||void 0===arguments[1]?{}:arguments[1],r=this._formatCustomValue(t,!1,n),i=r.rawNesting,o=r.formatted,a=r.value;if(o)return i?a:this._applyNestingFormatting(a,p(t));if(l(a))a=a.map(function(t){return e._formatValueForQueryString(t)}),a=this._applyNestingFormatting(a.join(", "),p(a));else{var u="undefined"==typeof a?"undefined":d(a);if(null===a)a="NULL";else if("boolean"===u)a=a?"TRUE":"FALSE";else if(f.isSquelBuilder(a))a=this._applyNestingFormatting(a.toString(),p(a));else if("number"!==u){if("string"===u&&this.options.stringFormatter)return this.options.stringFormatter(a);if(n.dontQuote)a=""+a;else{var s=this._escapeValue(a);a="'"+s+"'"}}}return a}},{key:"_applyNestingFormatting",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?!0:arguments[1];if(t&&"string"==typeof t&&e&&!this.options.rawNesting){var n="("===t.charAt(0)&&")"===t.charAt(t.length-1);if(n)for(var r=0,i=1;t.length-1>++r;){var o=t.charAt(r);if("("===o)i++;else if(")"===o&&(i--,1>i)){n=!1;break}}n||(t="("+t+")")}return t}},{key:"_buildString",value:function(t,e){var n=arguments.length<=2||void 0===arguments[2]?{}:arguments[2],r=n.nested,i=n.buildParameterized,o=n.formattingOptions;e=e||[],t=t||"";for(var a="",u=-1,s=[],c=this.options.parameterCharacter,h=0;t.length>h;)if(t.substr(h,c.length)===c){var v=e[++u];if(i)if(f.isSquelBuilder(v)){var d=v._toParamString({buildParameterized:i,nested:!0});a+=d.text,d.values.forEach(function(t){return s.push(t)})}else if(v=this._formatValueForParamArray(v,o),l(v)){var p=v.map(function(){return c}).join(", ");a+="("+p+")",v.forEach(function(t){return s.push(t)})}else a+=c,s.push(v);else a+=this._formatValueForQueryString(v,o);h+=c.length}else a+=t.charAt(h),h++;return{text:this._applyNestingFormatting(a,!!r),values:s}}},{key:"_buildManyStrings",value:function(t,e){for(var n=arguments.length<=2||void 0===arguments[2]?{}:arguments[2],r=[],i=[],o=0;t.length>o;++o){var l=t[o],a=e[o],u=this._buildString(l,a,{buildParameterized:n.buildParameterized,nested:!1}),s=u.text,c=u.values;r.push(s),c.forEach(function(t){return i.push(t)})}return r=r.join(this.options.separator),{text:r.length?this._applyNestingFormatting(r,!!n.nested):"",values:i}}},{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(i({},t,{buildParameterized:!0}))}}]),o}(f.Cloneable),f.Expression=function(r){function i(e){n(this,i);var r=t(this,Object.getPrototypeOf(i).call(this,e));return r._nodes=[],r}return e(i,r),v(i,[{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 t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],e=[],n=[],r=!0,i=!1,o=void 0;try{for(var l,a=this._nodes[Symbol.iterator]();!(r=(l=a.next()).done);r=!0){var u=l.value,s=u.type,c=u.expr,h=u.para,v=f.isSquelBuilder(c)?c._toParamString({buildParameterized:t.buildParameterized,nested:!0}):this._buildString(c,h,{buildParameterized:t.buildParameterized}),d=v.text,p=v.values;e.length&&e.push(s),e.push(d),p.forEach(function(t){return n.push(t)})}}catch(y){i=!0,o=y}finally{try{!r&&a["return"]&&a["return"]()}finally{if(i)throw o}}return e=e.join(" "),{text:this._applyNestingFormatting(e,!!t.nested),values:n}}}]),i}(f.BaseBuilder),f.Case=function(l){function a(e){var r=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];n(this,a);var l=t(this,Object.getPrototypeOf(a).call(this,r));return o(e)&&(r=e,e=null),e&&(l._fieldName=l._sanitizeField(e)),l.options=i({},f.DefaultQueryBuilderOptions,r),l._cases=[],l._elseValue=null,l}return e(a,l),v(a,[{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 t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],e="",n=[],i=!0,o=!1,l=void 0;try{for(var a,u=this._cases[Symbol.iterator]();!(i=(a=u.next()).done);i=!0){var s=a.value,c=s.expression,f=s.values,h=s.result;e=r(e," ");var v=this._buildString(c,f,{buildParameterized:t.buildParameterized,nested:!0});e+="WHEN "+v.text+" THEN "+this._formatValueForQueryString(h),v.values.forEach(function(t){return n.push(t)})}}catch(d){o=!0,l=d}finally{try{!i&&u["return"]&&u["return"]()}finally{if(o)throw l}}return e.length?(e+=" ELSE "+this._formatValueForQueryString(this._elseValue)+" END",this._fieldName&&(e=this._fieldName+" "+e),e="CASE "+e):e=this._formatValueForQueryString(this._elseValue),{text:e,values:n}}}]),a}(f.BaseBuilder),f.Block=function(r){function i(e){return n(this,i),t(this,Object.getPrototypeOf(i).call(this,e))}return e(i,r),v(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)||f.Block.prototype[n]||(t[n]=e[n])}),e=Object.getPrototypeOf(e);return t}}]),i}(f.BaseBuilder),f.StringBlock=function(r){function i(e,r){n(this,i);var o=t(this,Object.getPrototypeOf(i).call(this,e));return o._str=r,o}return e(i,r),v(i,[{key:"_toParamString",value:function(){arguments.length<=0||void 0===arguments[0]?{}:arguments[0];return{text:this._str,values:[]}}}]),i}(f.Block),f.FunctionBlock=function(r){function i(e){n(this,i);var r=t(this,Object.getPrototypeOf(i).call(this,e));return r._strings=[],r._values=[],r}return e(i,r),v(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}(f.Block),f.registerValueHandler(f.FunctionBlock,function(t){var e=arguments.length<=1||void 0===arguments[1]?!1:arguments[1];return e?t.toParam():t.toString()}),f.AbstractTableBlock=function(i){function o(e,r){n(this,o);var i=t(this,Object.getPrototypeOf(o).call(this,e));return i._tables=[],i}return e(o,i),v(o,[{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 t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],e="",n=[];if(this._hasTable()){var i=!0,o=!1,l=void 0;try{for(var a,u=this._tables[Symbol.iterator]();!(i=(a=u.next()).done);i=!0){var s=a.value,c=s.table,h=s.alias;e=r(e,", ");var v=void 0;if(f.isSquelBuilder(c)){var d=c._toParamString({buildParameterized:t.buildParameterized,nested:!0}),p=d.text,y=d.values;v=p,y.forEach(function(t){return n.push(t)})}else v=this._formatTableName(c);h&&(v+=" "+this._formatTableAlias(h)),e+=v}}catch(g){o=!0,l=g}finally{try{!i&&u["return"]&&u["return"]()}finally{if(o)throw l}}this.options.prefix&&(e=this.options.prefix+" "+e)}return{text:e,values:n}}}]),o}(f.Block),f.TargetTableBlock=function(r){function i(){return n(this,i),t(this,Object.getPrototypeOf(i).apply(this,arguments))}return e(i,r),v(i,[{key:"target",value:function(t){this._table(t)}}]),i}(f.AbstractTableBlock),f.UpdateTableBlock=function(r){function i(){return n(this,i),t(this,Object.getPrototypeOf(i).apply(this,arguments))}return e(i,r),v(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 h(Object.getPrototypeOf(i.prototype),"_toParamString",this).call(this,t)}}]),i}(f.AbstractTableBlock),f.FromTableBlock=function(r){function o(e){return n(this,o),t(this,Object.getPrototypeOf(o).call(this,i({},e,{prefix:"FROM"})))}return e(o,r),v(o,[{key:"from",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?null:arguments[1];this._table(t,e)}}]),o}(f.AbstractTableBlock),f.IntoTableBlock=function(r){function o(e){return n(this,o),t(this,Object.getPrototypeOf(o).call(this,i({},e,{prefix:"INTO",singleTable:!0})))}return e(o,r),v(o,[{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 h(Object.getPrototypeOf(o.prototype),"_toParamString",this).call(this,t)}}]),o}(f.AbstractTableBlock),f.GetFieldBlock=function(i){function o(e){n(this,o);var r=t(this,Object.getPrototypeOf(o).call(this,e));return r._fields=[],r}return e(o,i),v(o,[{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 t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],e=t.queryBuilder,n=t.buildParameterized,i="",o=[],l=!0,a=!1,u=void 0;try{for(var s,c=this._fields[Symbol.iterator]();!(l=(s=c.next()).done);l=!0){var h=s.value;i=r(i,", ");var v=h.name,d=h.alias,p=h.options;if("string"==typeof v)i+=this._formatFieldName(v,p);else{var y=v._toParamString({nested:!0,buildParameterized:n});i+=y.text,y.values.forEach(function(t){return o.push(t)})}d&&(i+=" AS "+this._formatFieldAlias(d))}}catch(g){a=!0,u=g}finally{try{!l&&c["return"]&&c["return"]()}finally{if(a)throw u}}if(!i.length){var _=e&&e.getBlock(f.FromTableBlock);_&&_._hasTable()&&(i="*")}return{text:i,values:o}}}]),o}(f.Block),f.AbstractSetFieldBlock=function(r){function i(e){n(this,i);var r=t(this,Object.getPrototypeOf(i).call(this,e));return r._reset(),r}return e(i,r),v(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":d(t)))throw new Error("Expected an object but got "+("undefined"==typeof t?"undefined":d(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":d(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}(f.Block),f.SetFieldBlock=function(i){function o(){return n(this,o),t(this,Object.getPrototypeOf(o).apply(this,arguments))}return e(o,i),v(o,[{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 t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],e=t.buildParameterized;if(0>=this._fields.length)throw new Error("set() needs to be called");for(var n="",i=[],o=0;o<this._fields.length;++o){n=r(n,", ");var l=this._formatFieldName(this._fields[o]),a=this._values[0][o];0>l.indexOf("=")&&(l=l+" = "+this.options.parameterCharacter);var u=this._buildString(l,[a],{buildParameterized:e,formattingOptions:this._valueOptions[0][o]});n+=u.text,u.values.forEach(function(t){return i.push(t)})}return{text:"SET "+n,values:i}}}]),o}(f.AbstractSetFieldBlock),f.InsertFieldValueBlock=function(i){function o(){return n(this,o),t(this,Object.getPrototypeOf(o).apply(this,arguments))}return e(o,i),v(o,[{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 t=this,e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],n=e.buildParameterized,i=this._fields.map(function(e){return t._formatFieldName(e)}).join(", "),o=[],l=[],a=0;a<this._values.length;++a){o[a]="";for(var u=0;u<this._values[a].length;++u){var s=this._buildString(this.options.parameterCharacter,[this._values[a][u]],{buildParameterized:n,formattingOptions:this._valueOptions[a][u]});s.values.forEach(function(t){return l.push(t)}),o[a]=r(o[a],", "),o[a]+=s.text}}return{text:i.length?"("+i+") VALUES ("+o.join("), (")+")":"",values:l}}}]),o}(f.AbstractSetFieldBlock),f.InsertFieldsFromQueryBlock=function(r){function i(e){n(this,i);var r=t(this,Object.getPrototypeOf(i).call(this,e));return r._fields=[],r._query=null,r}return e(i,r),v(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}(f.Block),f.DistinctBlock=function(r){function i(){return n(this,i),t(this,Object.getPrototypeOf(i).apply(this,arguments))}return e(i,r),v(i,[{key:"distinct",value:function(){this._useDistinct=!0}},{key:"_toParamString",value:function(){return{text:this._useDistinct?"DISTINCT":"",values:[]}}}]),i}(f.Block),f.GroupByBlock=function(r){function i(e){n(this,i);var r=t(this,Object.getPrototypeOf(i).call(this,e));return r._groups=[],r}return e(i,r),v(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}(f.Block),f.AbstractVerbSingleValueBlock=function(r){function i(e){n(this,i);var r=t(this,Object.getPrototypeOf(i).call(this,e));return r._value=null,r}return e(i,r),v(i,[{key:"_setValue",value:function(t){this._value=this._sanitizeLimitOffset(t)}},{key:"_toParamString",value:function(){var t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],e=null!==this._value?this.options.verb+" "+this.options.parameterCharacter:"",n=null!==this._value?[this._value]:[];return this._buildString(e,n,t)}}]),i}(f.Block),f.OffsetBlock=function(r){function o(e){return n(this,o),t(this,Object.getPrototypeOf(o).call(this,i({},e,{verb:"OFFSET"})))}return e(o,r),v(o,[{key:"offset",value:function(t){this._setValue(t)}}]),o}(f.AbstractVerbSingleValueBlock),f.LimitBlock=function(r){function o(e){return n(this,o),t(this,Object.getPrototypeOf(o).call(this,i({},e,{verb:"LIMIT"})))}return e(o,r),v(o,[{key:"limit",value:function(t){this._setValue(t)}}]),o}(f.AbstractVerbSingleValueBlock),f.AbstractConditionBlock=function(r){function i(e){n(this,i);var r=t(this,Object.getPrototypeOf(i).call(this,e));return r._conditions=[],r}return e(i,r),v(i,[{key:"_condition",value:function(t){t=this._sanitizeExpression(t);for(var e=arguments.length,n=Array(e>1?e-1:0),r=1;e>r;r++)n[r-1]=arguments[r];this._conditions.push({expr:t,values:n||[]})}},{key:"_toParamString",value:function(){var t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],e=[],n=[],r=!0,i=!1,o=void 0;try{for(var l,a=this._conditions[Symbol.iterator]();!(r=(l=a.next()).done);r=!0){var u=l.value,s=u.expr,c=u.values,h=f.isSquelBuilder(s)?s._toParamString({buildParameterized:t.buildParameterized}):this._buildString(s,c,{buildParameterized:t.buildParameterized});h.text.length&&e.push(h.text),h.values.forEach(function(t){return n.push(t)})}}catch(v){i=!0,o=v}finally{try{!r&&a["return"]&&a["return"]()}finally{if(i)throw o}}return e.length&&(e=e.join(") AND (")),{text:e.length?this.options.verb+" ("+e+")":"",values:n}}}]),i}(f.Block),f.WhereBlock=function(r){function o(e){return n(this,o),t(this,Object.getPrototypeOf(o).call(this,i({},e,{verb:"WHERE"})))}return e(o,r),v(o,[{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))}}]),o}(f.AbstractConditionBlock),f.HavingBlock=function(r){function o(e){return n(this,o),t(this,Object.getPrototypeOf(o).call(this,i({},e,{verb:"HAVING"})))}return e(o,r),v(o,[{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))}}]),o}(f.AbstractConditionBlock),f.OrderByBlock=function(i){function o(e){n(this,o);var r=t(this,Object.getPrototypeOf(o).call(this,e));return r._orders=[],r}return e(o,i),v(o,[{key:"order",value:function(t,e){t=this._sanitizeField(t),"string"!=typeof e&&(void 0===e?e="ASC":null!==e&&(e=e?"ASC":"DESC"));for(var n=arguments.length,r=Array(n>2?n-2:0),i=2;n>i;i++)r[i-2]=arguments[i];this._orders.push({field:t,dir:e,values:r||[]})}},{key:"_toParamString",value:function(){var t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],e="",n=[],i=!0,o=!1,a=void 0;try{for(var u,s=this._orders[Symbol.iterator]();!(i=(u=s.next()).done);i=!0){var c=u.value,f=c.field,h=c.dir,v=c.values;e=r(e,", ");var d=this._buildString(f,v,{buildParameterized:t.buildParameterized});e+=d.text,l(d.values)&&d.values.forEach(function(t){return n.push(t)}),null!==h&&(e+=" "+h)}}catch(p){o=!0,a=p}finally{try{!i&&s["return"]&&s["return"]()}finally{if(o)throw a}}return{text:e.length?"ORDER BY "+e:"",values:n}}}]),o}(f.Block),f.JoinBlock=function(i){function o(e){n(this,o);var r=t(this,Object.getPrototypeOf(o).call(this,e));return r._joins=[],r}return e(o,i),v(o,[{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 t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],e="",n=[],i=!0,o=!1,l=void 0;try{for(var a,u=this._joins[Symbol.iterator]();!(i=(a=u.next()).done);i=!0){var s=a.value,c=s.type,h=s.table,v=s.alias,d=s.condition;e=r(e,this.options.separator);var p=void 0;if(f.isSquelBuilder(h)){var y=h._toParamString({buildParameterized:t.buildParameterized,nested:!0});y.values.forEach(function(t){return n.push(t)}),p=y.text}else p=this._formatTableName(h);if(e+=c+" JOIN "+p,v&&(e+=" "+this._formatTableAlias(v)),d){e+=" ON ";var g=void 0;g=f.isSquelBuilder(d)?d._toParamString({buildParameterized:t.buildParameterized}):this._buildString(d,[],{buildParameterized:t.buildParameterized}),e+=this._applyNestingFormatting(g.text),g.values.forEach(function(t){return n.push(t)})}}}catch(_){o=!0,l=_}finally{try{!i&&u["return"]&&u["return"]()}finally{if(o)throw l}}return{text:e,values:n}}}]),o}(f.Block),f.UnionBlock=function(i){function o(e){n(this,o);var r=t(this,Object.getPrototypeOf(o).call(this,e));return r._unions=[],r}return e(o,i),v(o,[{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 t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],e="",n=[],i=!0,o=!1,l=void 0;try{for(var a,u=this._unions[Symbol.iterator]();!(i=(a=u.next()).done);i=!0){var s=a.value,c=s.type,h=s.table;e=r(e,this.options.separator);var v=void 0;if(h instanceof f.BaseBuilder){var d=h._toParamString({buildParameterized:t.buildParameterized,nested:!0});v=d.text,d.values.forEach(function(t){return n.push(t)})}else e=this._formatTableName(h);e+=c+" "+v}}catch(p){o=!0,l=p}finally{try{!i&&u["return"]&&u["return"]()}finally{if(o)throw l}}return{text:e,values:n}}}]),o}(f.Block),f.QueryBuilder=function(r){function o(e,r){n(this,o);var i=t(this,Object.getPrototypeOf(o).call(this,e));i.blocks=r||[];var l=!0,a=!1,u=void 0;try{for(var s,c=i.blocks[Symbol.iterator]();!(l=(s=c.next()).done);l=!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(p){a=!0,u=p}finally{try{!l&&c["return"]&&c["return"]()}finally{if(a)throw u}}return i}return e(o,r),v(o,[{key:"registerValueHandler",value:function(t,e){var n=!0,r=!1,i=void 0;try{for(var l,a=this.blocks[Symbol.iterator]();!(n=(l=a.next()).done);n=!0){var u=l.value;u.registerValueHandler(t,e)}}catch(s){r=!0,i=s}finally{try{!n&&a["return"]&&a["return"]()}finally{if(r)throw i}}return h(Object.getPrototypeOf(o.prototype),"registerValueHandler",this).call(this,t,e),this}},{key:"updateOptions",value:function(t){this.options=i({},this.options,t);var e=!0,n=!1,r=void 0;try{for(var o,l=this.blocks[Symbol.iterator]();!(e=(o=l.next()).done);e=!0){var a=o.value;a.options=i({},a.options,t)}}catch(u){n=!0,r=u}finally{try{!e&&l["return"]&&l["return"]()}finally{if(n)throw r}}}},{key:"_toParamString",value:function(){var t=this,e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];e=i({},this.options,e);var n=this.blocks.map(function(n){return n._toParamString({buildParameterized:e.buildParameterized,queryBuilder:t})}),r=n.map(function(t){return t.text}),o=n.map(function(t){return t.values}),l=r.filter(function(t){return 0<t.length}).join(e.separator),a=[];return o.forEach(function(t){return t.forEach(function(t){return a.push(t)})}),e.nested||e.numberedParameters&&!function(){var t=void 0!==e.numberedParametersStartAt?e.numberedParametersStartAt:1,n=e.parameterCharacter.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&");l=l.replace(new RegExp(n,"g"),function(){return""+e.numberedParametersPrefix+t++})}(),{text:this._applyNestingFormatting(l,!!e.nested),values:a}}},{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]}}]),o}(f.BaseBuilder),f.Select=function(r){function i(e){var r=arguments.length<=1||void 0===arguments[1]?null:arguments[1];return n(this,i),r=r||[new f.StringBlock(e,"SELECT"),new f.FunctionBlock(e),new f.DistinctBlock(e),new f.GetFieldBlock(e),new f.FromTableBlock(e),new f.JoinBlock(e),new f.WhereBlock(e),new f.GroupByBlock(e),new f.HavingBlock(e),new f.OrderByBlock(e),new f.LimitBlock(e),new f.OffsetBlock(e),new f.UnionBlock(e)],
t(this,Object.getPrototypeOf(i).call(this,e,r))}return e(i,r),i}(f.QueryBuilder),f.Update=function(r){function i(e){var r=arguments.length<=1||void 0===arguments[1]?null:arguments[1];return n(this,i),r=r||[new f.StringBlock(e,"UPDATE"),new f.UpdateTableBlock(e),new f.SetFieldBlock(e),new f.WhereBlock(e),new f.OrderByBlock(e),new f.LimitBlock(e)],t(this,Object.getPrototypeOf(i).call(this,e,r))}return e(i,r),i}(f.QueryBuilder),f.Delete=function(r){function o(e){var r=arguments.length<=1||void 0===arguments[1]?null:arguments[1];return n(this,o),r=r||[new f.StringBlock(e,"DELETE"),new f.TargetTableBlock(e),new f.FromTableBlock(i({},e,{singleTable:!0})),new f.JoinBlock(e),new f.WhereBlock(e),new f.OrderByBlock(e),new f.LimitBlock(e)],t(this,Object.getPrototypeOf(o).call(this,e,r))}return e(o,r),o}(f.QueryBuilder),f.Insert=function(r){function i(e){var r=arguments.length<=1||void 0===arguments[1]?null:arguments[1];return n(this,i),r=r||[new f.StringBlock(e,"INSERT"),new f.IntoTableBlock(e),new f.InsertFieldValueBlock(e),new f.InsertFieldsFromQueryBlock(e)],t(this,Object.getPrototypeOf(i).call(this,e,r))}return e(i,r),i}(f.QueryBuilder);var y={VERSION:"5.11.1",flavour:c,expr:function(t){return new f.Expression(t)},"case":function(t,e){return new f.Case(t,e)},select:function(t,e){return new f.Select(t,e)},update:function(t,e){return new f.Update(t,e)},insert:function(t,e){return new f.Insert(t,e)},"delete":function(t,e){return new f.Delete(t,e)},str:function(){var t=new f.FunctionBlock;return t["function"].apply(t,arguments),t},rstr:function(){var t=new f.FunctionBlock({rawNesting:!0});return t["function"].apply(t,arguments),t},registerValueHandler:f.registerValueHandler};return y.remove=y["delete"],y.cls=f,y}var h=function y(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:y(i,e,n)}if("value"in r)return r.value;var o=r.get;if(void 0!==o)return o.call(n)},v=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}}(),d="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=f();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=f(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(o){var l=o.cls;l.DefaultQueryBuilderOptions.replaceSingleQuotes=!0,l.DefaultQueryBuilderOptions.autoQuoteAliasNames=!1,l.DefaultQueryBuilderOptions.numberedParametersPrefix="@",o.registerValueHandler(Date,function(t){return"'"+t.getUTCFullYear()+"-"+(t.getUTCMonth()+1)+"-"+t.getUTCDate()+" "+t.getUTCHours()+":"+t.getUTCMinutes()+":"+t.getUTCSeconds()+"'"}),l.MssqlLimitOffsetTopBlock=function(r){function i(r){n(this,i);var o=t(this,Object.getPrototypeOf(i).call(this,r));o._limits=null,o._offsets=null;var a=function(t){t=this._sanitizeLimitOffset(t),this._parent._limits=t};return o.ParentBlock=function(r){function i(e){n(this,i);var r=t(this,Object.getPrototypeOf(i).call(this,e.options));return r._parent=e,r}return e(i,r),i}(l.Block),o.LimitBlock=function(r){function i(e){n(this,i);var r=t(this,Object.getPrototypeOf(i).call(this,e));return r.limit=a,r}return e(i,r),v(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(r){function i(e){n(this,i);var r=t(this,Object.getPrototypeOf(i).call(this,e));return r.top=a,r}return e(i,r),v(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(r){function i(){return n(this,i),t(this,Object.getPrototypeOf(i).apply(this,arguments))}return e(i,r),v(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 e(i,r),v(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}(l.Block),l.MssqlUpdateTopBlock=function(r){function i(e){n(this,i);var r=t(this,Object.getPrototypeOf(i).call(this,e));return r._limits=null,r.limit=r.top=function(t){r._limits=r._sanitizeLimitOffset(t)},r}return e(i,r),v(i,[{key:"_toParamString",value:function(){return{text:this._limits?"TOP ("+this._limits+")":"",values:[]}}}]),i}(l.Block),l.MssqlInsertFieldValueBlock=function(r){function i(e){n(this,i);var r=t(this,Object.getPrototypeOf(i).call(this,e));return r._outputs=[],r}return e(i,r),v(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=h(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}(l.InsertFieldValueBlock),l.MssqlUpdateDeleteOutputBlock=function(i){function o(e){n(this,o);var r=t(this,Object.getPrototypeOf(o).call(this,e));return r._outputs=[],r}return e(o,i),v(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,i=!1,o=void 0;try{for(var l,a=this._outputs[Symbol.iterator]();!(n=(l=a.next()).done);n=!0){var u=l.value;e=r(e,", "),e+=u.name,u.alias&&(e+=" AS "+this._formatFieldAlias(u.alias))}}catch(s){i=!0,o=s}finally{try{!n&&a["return"]&&a["return"]()}finally{if(i)throw o}}e="OUTPUT "+e}return{text:e,values:[]}}}]),o}(l.Block),l.Select=function(r){function i(e){var r=arguments.length<=1||void 0===arguments[1]?null:arguments[1];n(this,i);var o=new l.MssqlLimitOffsetTopBlock(e);return r=r||[new l.StringBlock(e,"SELECT"),new l.DistinctBlock(e),o.TOP(),new l.GetFieldBlock(e),new l.FromTableBlock(e),new l.JoinBlock(e),new l.WhereBlock(e),new l.GroupByBlock(e),new l.OrderByBlock(e),o.OFFSET(),o.LIMIT(),new l.UnionBlock(e)],t(this,Object.getPrototypeOf(i).call(this,e,r))}return e(i,r),i}(l.QueryBuilder),l.Update=function(r){function i(e){var r=arguments.length<=1||void 0===arguments[1]?null:arguments[1];return n(this,i),r=r||[new l.StringBlock(e,"UPDATE"),new l.MssqlUpdateTopBlock(e),new l.UpdateTableBlock(e),new l.SetFieldBlock(e),new l.MssqlUpdateDeleteOutputBlock(e),new l.WhereBlock(e)],t(this,Object.getPrototypeOf(i).call(this,e,r))}return e(i,r),i}(l.QueryBuilder),l.Delete=function(r){function o(e){var r=arguments.length<=1||void 0===arguments[1]?null:arguments[1];return n(this,o),r=r||[new l.StringBlock(e,"DELETE"),new l.TargetTableBlock(e),new l.FromTableBlock(i({},e,{singleTable:!0})),new l.JoinBlock(e),new l.MssqlUpdateDeleteOutputBlock(i({},e,{forDelete:!0})),new l.WhereBlock(e),new l.OrderByBlock(e),new l.LimitBlock(e)],t(this,Object.getPrototypeOf(o).call(this,e,r))}return e(o,r),o}(l.QueryBuilder),l.Insert=function(r){function i(e){var r=arguments.length<=1||void 0===arguments[1]?null:arguments[1];return n(this,i),r=r||[new l.StringBlock(e,"INSERT"),new l.IntoTableBlock(e),new l.MssqlInsertFieldValueBlock(e),new l.InsertFieldsFromQueryBlock(e)],t(this,Object.getPrototypeOf(i).call(this,e,r))}return e(i,r),i}(l.QueryBuilder)},p.flavours.mysql=function(i){var o=i.cls;o.MysqlOnDuplicateKeyUpdateBlock=function(i){function o(){return n(this,o),t(this,Object.getPrototypeOf(o).apply(this,arguments))}return e(o,i),v(o,[{key:"onDupUpdate",value:function(t,e,n){this._set(t,e,n)}},{key:"_toParamString",value:function(){for(var t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],e="",n=[],i=0;i<this._fields.length;++i){e=r(e,", ");var o=this._fields[i],l=this._values[0][i],a=this._valueOptions[0][i];if("undefined"==typeof l)e+=o;else{var u=this._buildString(o+" = "+this.options.parameterCharacter,[l],{buildParameterized:t.buildParameterized,formattingOptions:a});e+=u.text,u.values.forEach(function(t){return n.push(t)})}}return{text:e.length?"ON DUPLICATE KEY UPDATE "+e:"",values:n}}}]),o}(o.AbstractSetFieldBlock),o.Insert=function(r){function i(e){var r=arguments.length<=1||void 0===arguments[1]?null:arguments[1];return n(this,i),r=r||[new o.StringBlock(e,"INSERT"),new o.IntoTableBlock(e),new o.InsertFieldValueBlock(e),new o.InsertFieldsFromQueryBlock(e),new o.MysqlOnDuplicateKeyUpdateBlock(e)],t(this,Object.getPrototypeOf(i).call(this,e,r))}return e(i,r),i}(o.QueryBuilder),o.Replace=function(r){function i(e){var r=arguments.length<=1||void 0===arguments[1]?null:arguments[1];return n(this,i),r=r||[new o.StringBlock(e,"REPLACE"),new o.IntoTableBlock(e),new o.InsertFieldValueBlock(e),new o.InsertFieldsFromQueryBlock(e)],t(this,Object.getPrototypeOf(i).call(this,e,r))}return e(i,r),i}(o.QueryBuilder),i.replace=function(t,e){return new o.Replace(t,e)}},p.flavours.postgres=function(o){var a=o.cls;a.DefaultQueryBuilderOptions.numberedParameters=!0,a.DefaultQueryBuilderOptions.numberedParametersStartAt=1,a.DefaultQueryBuilderOptions.autoQuoteAliasNames=!1,a.DefaultQueryBuilderOptions.useAsForTableAliasNames=!0,a.PostgresOnConflictKeyUpdateBlock=function(i){function o(){return n(this,o),t(this,Object.getPrototypeOf(o).apply(this,arguments))}return e(o,i),v(o,[{key:"onConflict",value:function(t,e){var n=this;this._onConflict=!0,t&&(l(t)||(t=[t]),this._dupFields=t.map(this._sanitizeField.bind(this)),e&&Object.keys(e).forEach(function(t){n._set(t,e[t])}))}},{key:"_toParamString",value:function(){for(var t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],e="",n=[],i=0;i<this._fields.length;++i){e=r(e,", ");var o=this._fields[i],l=this._values[0][i],a=this._valueOptions[0][i];if("undefined"==typeof l)e+=o;else{var u=this._buildString(o+" = "+this.options.parameterCharacter,[l],{buildParameterized:t.buildParameterized,formattingOptions:a});e+=u.text,u.values.forEach(function(t){return n.push(t)})}}var s={text:"",values:n};if(this._onConflict){var c=this._dupFields?"("+this._dupFields.join(", ")+") ":"",f=e.length?"UPDATE SET "+e:"NOTHING";s.text="ON CONFLICT "+c+"DO "+f}return s}}]),o}(a.AbstractSetFieldBlock),a.ReturningBlock=function(i){function o(e){n(this,o);var r=t(this,Object.getPrototypeOf(o).call(this,e));return r._fields=[],r}return e(o,i),v(o,[{key:"returning",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 t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],e=(t.queryBuilder,t.buildParameterized),n="",i=[],o=!0,l=!1,a=void 0;try{for(var u,s=this._fields[Symbol.iterator]();!(o=(u=s.next()).done);o=!0){var c=u.value;n=r(n,", ");var f=c.name,h=c.alias,v=c.options;if("string"==typeof f)n+=this._formatFieldName(f,v);else{var d=f._toParamString({nested:!0,buildParameterized:e});n+=d.text,d.values.forEach(function(t){return i.push(t)})}h&&(n+=" AS "+this._formatFieldAlias(h))}}catch(p){l=!0,a=p}finally{try{!o&&s["return"]&&s["return"]()}finally{if(l)throw a}}return{text:n.length>0?"RETURNING "+n:"",values:i}}}]),o}(a.Block),a.WithBlock=function(r){function i(e){n(this,i);var r=t(this,Object.getPrototypeOf(i).call(this,e));return r._tables=[],r}return e(i,r),v(i,[{key:"with",value:function(t,e){this._tables.push({alias:t,table:e})}},{key:"_toParamString",value:function(){var t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],e=[],n=[],r=!0,i=!1,o=void 0;try{for(var l,a=this._tables[Symbol.iterator]();!(r=(l=a.next()).done);r=!0){var u=l.value,s=u.alias,c=u.table,f=c._toParamString({buildParameterized:t.buildParameterized,nested:!0});e.push(s+" AS "+f.text),f.values.forEach(function(t){return n.push(t)})}}catch(h){i=!0,o=h}finally{try{!r&&a["return"]&&a["return"]()}finally{if(i)throw o}}return{text:e.length?"WITH "+e.join(", "):"",values:n}}}]),i}(a.Block),a.DistinctOnBlock=function(r){function i(e){n(this,i);var r=t(this,Object.getPrototypeOf(i).call(this,e));return r._distinctFields=[],r}return e(i,r),v(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(r){function i(e){var r=arguments.length<=1||void 0===arguments[1]?null:arguments[1];return n(this,i),r=r||[new a.WithBlock(e),new a.StringBlock(e,"SELECT"),new a.FunctionBlock(e),new a.DistinctOnBlock(e),new a.GetFieldBlock(e),new a.FromTableBlock(e),new a.JoinBlock(e),new a.WhereBlock(e),new a.GroupByBlock(e),new a.HavingBlock(e),new a.OrderByBlock(e),new a.LimitBlock(e),new a.OffsetBlock(e),new a.UnionBlock(e)],t(this,Object.getPrototypeOf(i).call(this,e,r))}return e(i,r),i}(a.QueryBuilder),a.Insert=function(r){function i(e){var r=arguments.length<=1||void 0===arguments[1]?null:arguments[1];return n(this,i),r=r||[new a.WithBlock(e),new a.StringBlock(e,"INSERT"),new a.IntoTableBlock(e),new a.InsertFieldValueBlock(e),new a.InsertFieldsFromQueryBlock(e),new a.PostgresOnConflictKeyUpdateBlock(e),new a.ReturningBlock(e)],t(this,Object.getPrototypeOf(i).call(this,e,r))}return e(i,r),i}(a.QueryBuilder),a.Update=function(r){function i(e){var r=arguments.length<=1||void 0===arguments[1]?null:arguments[1];return n(this,i),r=r||[new a.WithBlock(e),new a.StringBlock(e,"UPDATE"),new a.UpdateTableBlock(e),new a.SetFieldBlock(e),new a.FromTableBlock(e),new a.WhereBlock(e),new a.OrderByBlock(e),new a.LimitBlock(e),new a.ReturningBlock(e)],t(this,Object.getPrototypeOf(i).call(this,e,r))}return e(i,r),i}(a.QueryBuilder),a.Delete=function(r){function o(e){var r=arguments.length<=1||void 0===arguments[1]?null:arguments[1];return n(this,o),r=r||[new a.WithBlock(e),new a.StringBlock(e,"DELETE"),new a.TargetTableBlock(e),new a.FromTableBlock(i({},e,{singleTable:!0})),new a.JoinBlock(e),new a.WhereBlock(e),new a.OrderByBlock(e),new a.LimitBlock(e),new a.ReturningBlock(e)],t(this,Object.getPrototypeOf(o).call(this,e,r))}return e(o,r),o}(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,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 e(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 n(t,e){return t.length?t+e:t}function i(t){for(var e=arguments.length,r=Array(e>1?e-1:0),n=1;n<e;n++)r[n-1]=arguments[n];if(t&&r){var i=!0,o=!1,l=void 0;try{for(var a,u=function(){var e=a.value;"object"===("undefined"==typeof e?"undefined":d(e))&&Object.getOwnPropertyNames(e).forEach(function(r){t[r]=e[r]})},s=r[Symbol.iterator]();!(i=(a=s.next()).done);i=!0)u()}catch(c){o=!0,l=c}finally{try{!i&&s["return"]&&s["return"]()}finally{if(o)throw l}}}return t}function o(t){return t&&t.constructor.prototype===Object.prototype}function l(t){return t&&t.constructor.prototype===Array.prototype}function a(t){if(!t)return t;if("function"==typeof t.clone)return t.clone();if(o(t)||l(t)){var e=new t.constructor;return Object.getOwnPropertyNames(t).forEach(function(r){"function"!=typeof t[r]&&(e[r]=a(t[r]))}),e}return JSON.parse(JSON.stringify(t))}function u(t,e,r){var n="undefined"==typeof e?"undefined":d(e);if("function"!==n&&"string"!==n)throw new Error("type must be a class constructor or string");if("function"!=typeof r)throw new Error("handler must be a function");var i=!0,o=!1,l=void 0;try{for(var a,u=t[Symbol.iterator]();!(i=(a=u.next()).done);i=!0){var s=a.value;if(s.type===e)return void(s.handler=r)}}catch(c){o=!0,l=c}finally{try{!i&&u["return"]&&u["return"]()}finally{if(o)throw l}}t.push({type:e,handler:r})}function s(t,e,r){return c(t,e)||c(t,r)}function c(t,e){for(var r=0;r<e.length;r++){var n=e[r];if(("undefined"==typeof t?"undefined":d(t))===n.type||"string"!=typeof n.type&&t instanceof n.type)return n.handler}}function f(){var c=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,f={isSquelBuilder:function(t){return t&&!!t._toParamString}},_=function(t){return!f.isSquelBuilder(t)||!t.options.rawNesting};f.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,rawNesting:!1},f.globalValueHandlers=[],f.registerValueHandler=function(t,e){u(f.globalValueHandlers,t,e)},f.Cloneable=function(){function t(){r(this,t)}return v(t,[{key:"clone",value:function(){var t=new this.constructor;return i(t,a(i({},this)))}}]),t}(),f.BaseBuilder=function(n){function o(e){r(this,o);var n=t(this,(o.__proto__||Object.getPrototypeOf(o)).call(this)),l=JSON.parse(JSON.stringify(f.DefaultQueryBuilderOptions));return["stringFormatter"].forEach(function(t){l[t]=f.DefaultQueryBuilderOptions[t]}),n.options=i({},l,e),n}return e(o,n),v(o,[{key:"registerValueHandler",value:function(t,e){return u(this.options.valueHandlers,t,e),this}},{key:"_sanitizeExpression",value:function(t){if(!f.isSquelBuilder(t)&&"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 f.isSquelBuilder(t)||(t=this._sanitizeName(t,"field name")),t}},{key:"_sanitizeBaseBuilder",value:function(t){if(f.isSquelBuilder(t))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":d(t);if(null===t);else if("string"===e||"number"===e||"boolean"===e);else if(f.isSquelBuilder(t));else{var r=!!s(t,this.options.valueHandlers,f.globalValueHandlers);if(!r)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=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(this.options.autoQuoteFieldNames){var r=this.options.nameQuoteCharacter;t=e.ignorePeriodsForFieldNameQuotes?""+r+t+r:t.split(".").map(function(t){return"*"===t?t:""+r+t+r}).join(".")}return t}},{key:"_formatCustomValue",value:function(t,e,r){var n=s(t,this.options.valueHandlers,f.globalValueHandlers);return n&&(t=n(t,e,r),t&&t.rawNesting)?{formatted:!0,rawNesting:!0,value:t.value}:{formatted:!!n,value:t}}},{key:"_formatValueForParamArray",value:function(t){var e=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return l(t)?t.map(function(t){return e._formatValueForParamArray(t,r)}):this._formatCustomValue(t,!0,r).value}},{key:"_formatValueForQueryString",value:function(t){var e=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=this._formatCustomValue(t,!1,r),i=n.rawNesting,o=n.formatted,a=n.value;if(o)return i?a:this._applyNestingFormatting(a,_(t));if(l(a))a=a.map(function(t){return e._formatValueForQueryString(t)}),a=this._applyNestingFormatting(a.join(", "),_(a));else{var u="undefined"==typeof a?"undefined":d(a);if(null===a)a="NULL";else if("boolean"===u)a=a?"TRUE":"FALSE";else if(f.isSquelBuilder(a))a=this._applyNestingFormatting(a.toString(),_(a));else if("number"!==u){if("string"===u&&this.options.stringFormatter)return this.options.stringFormatter(a);if(r.dontQuote)a=""+a;else{var s=this._escapeValue(a);a="'"+s+"'"}}}return a}},{key:"_applyNestingFormatting",value:function(t){var e=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];if(t&&"string"==typeof t&&e&&!this.options.rawNesting){var r="("===t.charAt(0)&&")"===t.charAt(t.length-1);if(r)for(var n=0,i=1;t.length-1>++n;){var o=t.charAt(n);if("("===o)i++;else if(")"===o&&(i--,1>i)){r=!1;break}}r||(t="("+t+")")}return t}},{key:"_buildString",value:function(t,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},n=r.nested,i=r.buildParameterized,o=r.formattingOptions;e=e||[],t=t||"";for(var a="",u=-1,s=[],c=this.options.parameterCharacter,h=0;t.length>h;)if(t.substr(h,c.length)===c){var v=e[++u];if(i)if(f.isSquelBuilder(v)){var d=v._toParamString({buildParameterized:i,nested:!0});a+=d.text,d.values.forEach(function(t){return s.push(t)})}else if(v=this._formatValueForParamArray(v,o),l(v)){var _=v.map(function(){return c}).join(", ");a+="("+_+")",v.forEach(function(t){return s.push(t)})}else a+=c,s.push(v);else a+=this._formatValueForQueryString(v,o);h+=c.length}else a+=t.charAt(h),h++;return{text:this._applyNestingFormatting(a,!!n),values:s}}},{key:"_buildManyStrings",value:function(t,e){for(var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},n=[],i=[],o=0;t.length>o;++o){var l=t[o],a=e[o],u=this._buildString(l,a,{buildParameterized:r.buildParameterized,nested:!1}),s=u.text,c=u.values;n.push(s),c.forEach(function(t){return i.push(t)})}return n=n.join(this.options.separator),{text:n.length?this._applyNestingFormatting(n,!!r.nested):"",values:i}}},{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(i({},t,{buildParameterized:!0}))}}]),o}(f.Cloneable),f.Expression=function(n){function i(e){r(this,i);var n=t(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,e));return n._nodes=[],n}return e(i,n),v(i,[{key:"and",value:function(t){for(var e=arguments.length,r=Array(e>1?e-1:0),n=1;n<e;n++)r[n-1]=arguments[n];return t=this._sanitizeExpression(t),this._nodes.push({type:"AND",expr:t,para:r}),this}},{key:"or",value:function(t){for(var e=arguments.length,r=Array(e>1?e-1:0),n=1;n<e;n++)r[n-1]=arguments[n];return t=this._sanitizeExpression(t),this._nodes.push({type:"OR",expr:t,para:r}),this}},{key:"_toParamString",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=[],r=[],n=!0,i=!1,o=void 0;try{for(var l,a=this._nodes[Symbol.iterator]();!(n=(l=a.next()).done);n=!0){var u=l.value,s=u.type,c=u.expr,h=u.para,v=f.isSquelBuilder(c)?c._toParamString({buildParameterized:t.buildParameterized,nested:!0}):this._buildString(c,h,{buildParameterized:t.buildParameterized}),d=v.text,_=v.values;e.length&&e.push(s),e.push(d),_.forEach(function(t){return r.push(t)})}}catch(p){i=!0,o=p}finally{try{!n&&a["return"]&&a["return"]()}finally{if(i)throw o}}return e=e.join(" "),{text:this._applyNestingFormatting(e,!!t.nested),values:r}}}]),i}(f.BaseBuilder),f.Case=function(l){function a(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};r(this,a);var l=t(this,(a.__proto__||Object.getPrototypeOf(a)).call(this,n));return o(e)&&(n=e,e=null),e&&(l._fieldName=l._sanitizeField(e)),l.options=i({},f.DefaultQueryBuilderOptions,n),l._cases=[],l._elseValue=null,l}return e(a,l),v(a,[{key:"when",value:function(t){for(var e=arguments.length,r=Array(e>1?e-1:0),n=1;n<e;n++)r[n-1]=arguments[n];return this._cases.unshift({expression:t,values:r||[]}),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 t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e="",r=[],i=!0,o=!1,l=void 0;try{for(var a,u=this._cases[Symbol.iterator]();!(i=(a=u.next()).done);i=!0){var s=a.value,c=s.expression,f=s.values,h=s.result;e=n(e," ");var v=this._buildString(c,f,{buildParameterized:t.buildParameterized,nested:!0});e+="WHEN "+v.text+" THEN "+this._formatValueForQueryString(h),v.values.forEach(function(t){return r.push(t)})}}catch(d){o=!0,l=d}finally{try{!i&&u["return"]&&u["return"]()}finally{if(o)throw l}}return e.length?(e+=" ELSE "+this._formatValueForQueryString(this._elseValue)+" END",this._fieldName&&(e=this._fieldName+" "+e),e="CASE "+e):e=this._formatValueForQueryString(this._elseValue),{text:e,values:r}}}]),a}(f.BaseBuilder),f.Block=function(n){function i(e){return r(this,i),t(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,e))}return e(i,n),v(i,[{key:"exposedMethods",value:function(){for(var t={},e=this;e;)Object.getOwnPropertyNames(e).forEach(function(r){"constructor"===r||"function"!=typeof e[r]||"_"===r.charAt(0)||f.Block.prototype[r]||(t[r]=e[r])}),e=Object.getPrototypeOf(e);return t}}]),i}(f.BaseBuilder),f.StringBlock=function(n){function i(e,n){r(this,i);var o=t(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,e));return o._str=n,o}return e(i,n),v(i,[{key:"_toParamString",value:function(){arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return{text:this._str,values:[]}}}]),i}(f.Block),f.FunctionBlock=function(n){function i(e){r(this,i);var n=t(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,e));return n._strings=[],n._values=[],n}return e(i,n),v(i,[{key:"function",value:function(t){this._strings.push(t);for(var e=arguments.length,r=Array(e>1?e-1:0),n=1;n<e;n++)r[n-1]=arguments[n];this._values.push(r)}},{key:"_toParamString",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return this._buildManyStrings(this._strings,this._values,t)}}]),i}(f.Block),f.registerValueHandler(f.FunctionBlock,function(t){var e=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return e?t.toParam():t.toString()}),f.AbstractTableBlock=function(i){function o(e,n){r(this,o);var i=t(this,(o.__proto__||Object.getPrototypeOf(o)).call(this,e));return i._tables=[],i}return e(o,i),v(o,[{key:"_table",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;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 t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e="",r=[];if(this._hasTable()){var i=!0,o=!1,l=void 0;try{for(var a,u=this._tables[Symbol.iterator]();!(i=(a=u.next()).done);i=!0){var s=a.value,c=s.table,h=s.alias;e=n(e,", ");var v=void 0;if(f.isSquelBuilder(c)){var d=c._toParamString({buildParameterized:t.buildParameterized,nested:!0}),_=d.text,p=d.values;v=_,p.forEach(function(t){return r.push(t)})}else v=this._formatTableName(c);h&&(v+=" "+this._formatTableAlias(h)),e+=v}}catch(y){o=!0,l=y}finally{try{!i&&u["return"]&&u["return"]()}finally{if(o)throw l}}this.options.prefix&&(e=this.options.prefix+" "+e)}return{text:e,values:r}}}]),o}(f.Block),f.TargetTableBlock=function(n){function i(){return r(this,i),t(this,(i.__proto__||Object.getPrototypeOf(i)).apply(this,arguments))}return e(i,n),v(i,[{key:"target",value:function(t){this._table(t)}}]),i}(f.AbstractTableBlock),f.UpdateTableBlock=function(n){function i(){return r(this,i),t(this,(i.__proto__||Object.getPrototypeOf(i)).apply(this,arguments))}return e(i,n),v(i,[{key:"table",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;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 h(i.prototype.__proto__||Object.getPrototypeOf(i.prototype),"_toParamString",this).call(this,t)}}]),i}(f.AbstractTableBlock),f.FromTableBlock=function(n){function o(e){return r(this,o),t(this,(o.__proto__||Object.getPrototypeOf(o)).call(this,i({},e,{prefix:"FROM"})))}return e(o,n),v(o,[{key:"from",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;this._table(t,e)}}]),o}(f.AbstractTableBlock),f.IntoTableBlock=function(n){function o(e){return r(this,o),t(this,(o.__proto__||Object.getPrototypeOf(o)).call(this,i({},e,{prefix:"INTO",singleTable:!0})))}return e(o,n),v(o,[{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 h(o.prototype.__proto__||Object.getPrototypeOf(o.prototype),"_toParamString",this).call(this,t)}}]),o}(f.AbstractTableBlock),f.GetFieldBlock=function(i){function o(e){r(this,o);var n=t(this,(o.__proto__||Object.getPrototypeOf(o)).call(this,e));return n._fields=[],n}return e(o,i),v(o,[{key:"fields",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(l(t)){var r=!0,n=!1,i=void 0;try{for(var o,a=t[Symbol.iterator]();!(r=(o=a.next()).done);r=!0){var u=o.value;this.field(u,null,e)}}catch(s){n=!0,i=s}finally{try{!r&&a["return"]&&a["return"]()}finally{if(n)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]?arguments[1]:null,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};e=e?this._sanitizeFieldAlias(e):e,t=this._sanitizeField(t);var n=this._fields.filter(function(r){return r.name===t&&r.alias===e});return n.length?this:void this._fields.push({name:t,alias:e,options:r})}},{key:"_toParamString",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=t.queryBuilder,r=t.buildParameterized,i="",o=[],l=!0,a=!1,u=void 0;try{for(var s,c=this._fields[Symbol.iterator]();!(l=(s=c.next()).done);l=!0){var h=s.value;i=n(i,", ");var v=h.name,d=h.alias,_=h.options;if("string"==typeof v)i+=this._formatFieldName(v,_);else{var p=v._toParamString({nested:!0,buildParameterized:r});i+=p.text,p.values.forEach(function(t){return o.push(t)})}d&&(i+=" AS "+this._formatFieldAlias(d))}}catch(y){a=!0,u=y}finally{try{!l&&c["return"]&&c["return"]()}finally{if(a)throw u}}if(!i.length){var g=e&&e.getBlock(f.FromTableBlock);g&&g._hasTable()&&(i="*")}return{text:i,values:o}}}]),o}(f.Block),f.AbstractSetFieldBlock=function(n){function i(e){r(this,i);var n=t(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,e));return n._reset(),n}return e(i,n),v(i,[{key:"_reset",value:function(){this._fields=[],this._values=[[]],this._valueOptions=[[]]}},{key:"_set",value:function(t,e){var r=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 n=this._fields.indexOf(t);-1===n&&(this._fields.push(t),n=this._fields.length-1),this._values[0][n]=e,this._valueOptions[0][n]=r}},{key:"_setFields",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if("object"!==("undefined"==typeof t?"undefined":d(t)))throw new Error("Expected an object but got "+("undefined"==typeof t?"undefined":d(t)));for(var r in t)this._set(r,t[r],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":d(t)));this._reset();for(var r=0;t.length>r;++r){var n=t[r];for(var i in n){var o=n[i];i=this._sanitizeField(i),o=this._sanitizeValue(o);var a=this._fields.indexOf(i);if(0<r&&-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[r])||(this._values[r]=[],this._valueOptions[r]=[]),this._values[r][a]=o,this._valueOptions[r][a]=e}}}}]),i}(f.Block),f.SetFieldBlock=function(i){function o(){return r(this,o),t(this,(o.__proto__||Object.getPrototypeOf(o)).apply(this,arguments))}return e(o,i),v(o,[{key:"set",value:function(t,e,r){this._set(t,e,r)}},{key:"setFields",value:function(t,e){this._setFields(t,e)}},{key:"_toParamString",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=t.buildParameterized;if(0>=this._fields.length)throw new Error("set() needs to be called");for(var r="",i=[],o=0;o<this._fields.length;++o){r=n(r,", ");var l=this._formatFieldName(this._fields[o]),a=this._values[0][o];0>l.indexOf("=")&&(l=l+" = "+this.options.parameterCharacter);var u=this._buildString(l,[a],{buildParameterized:e,formattingOptions:this._valueOptions[0][o]});r+=u.text,u.values.forEach(function(t){return i.push(t)})}return{text:"SET "+r,values:i}}}]),o}(f.AbstractSetFieldBlock),f.InsertFieldValueBlock=function(i){function o(){return r(this,o),t(this,(o.__proto__||Object.getPrototypeOf(o)).apply(this,arguments))}return e(o,i),v(o,[{key:"set",value:function(t,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};this._set(t,e,r)}},{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 t=this,e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.buildParameterized,i=this._fields.map(function(e){return t._formatFieldName(e)}).join(", "),o=[],l=[],a=0;a<this._values.length;++a){o[a]="";for(var u=0;u<this._values[a].length;++u){var s=this._buildString(this.options.parameterCharacter,[this._values[a][u]],{buildParameterized:r,formattingOptions:this._valueOptions[a][u]});s.values.forEach(function(t){return l.push(t)}),o[a]=n(o[a],", "),o[a]+=s.text}}return{text:i.length?"("+i+") VALUES ("+o.join("), (")+")":"",values:l}}}]),o}(f.AbstractSetFieldBlock),f.InsertFieldsFromQueryBlock=function(n){function i(e){r(this,i);var n=t(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,e));return n._fields=[],n._query=null,n}return e(i,n),v(i,[{key:"fromQuery",value:function(t,e){var r=this;this._fields=t.map(function(t){return r._sanitizeField(t)}),this._query=this._sanitizeBaseBuilder(e)}},{key:"_toParamString",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e="",r=[];if(this._fields.length&&this._query){var n=this._query._toParamString({buildParameterized:t.buildParameterized,nested:!0}),i=n.text,o=n.values;e="("+this._fields.join(", ")+") "+this._applyNestingFormatting(i),r=o}return{text:e,values:r}}}]),i}(f.Block),f.DistinctBlock=function(n){function i(){return r(this,i),t(this,(i.__proto__||Object.getPrototypeOf(i)).apply(this,arguments))}return e(i,n),v(i,[{key:"distinct",value:function(){this._useDistinct=!0}},{key:"_toParamString",value:function(){return{text:this._useDistinct?"DISTINCT":"",values:[]}}}]),i}(f.Block),f.GroupByBlock=function(n){function i(e){r(this,i);var n=t(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,e));return n._groups=[],n}return e(i,n),v(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}(f.Block),f.AbstractVerbSingleValueBlock=function(n){function i(e){r(this,i);var n=t(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,e));return n._value=null,n}return e(i,n),v(i,[{key:"_setValue",value:function(t){this._value=null!==t?this._sanitizeLimitOffset(t):t}},{key:"_toParamString",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=null!==this._value?this.options.verb+" "+this.options.parameterCharacter:"",r=null!==this._value?[this._value]:[];return this._buildString(e,r,t)}}]),i}(f.Block),f.OffsetBlock=function(n){function o(e){return r(this,o),t(this,(o.__proto__||Object.getPrototypeOf(o)).call(this,i({},e,{verb:"OFFSET"})))}return e(o,n),v(o,[{key:"offset",value:function(t){this._setValue(t)}}]),o}(f.AbstractVerbSingleValueBlock),f.LimitBlock=function(n){function o(e){return r(this,o),t(this,(o.__proto__||Object.getPrototypeOf(o)).call(this,i({},e,{verb:"LIMIT"})))}return e(o,n),v(o,[{key:"limit",value:function(t){this._setValue(t)}}]),o}(f.AbstractVerbSingleValueBlock),f.AbstractConditionBlock=function(n){function i(e){r(this,i);var n=t(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,e));return n._conditions=[],n}return e(i,n),v(i,[{key:"_condition",value:function(t){t=this._sanitizeExpression(t);for(var e=arguments.length,r=Array(e>1?e-1:0),n=1;n<e;n++)r[n-1]=arguments[n];this._conditions.push({expr:t,values:r||[]})}},{key:"_toParamString",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=[],r=[],n=!0,i=!1,o=void 0;try{for(var l,a=this._conditions[Symbol.iterator]();!(n=(l=a.next()).done);n=!0){var u=l.value,s=u.expr,c=u.values,h=f.isSquelBuilder(s)?s._toParamString({buildParameterized:t.buildParameterized}):this._buildString(s,c,{buildParameterized:t.buildParameterized});h.text.length&&e.push(h.text),h.values.forEach(function(t){return r.push(t)})}}catch(v){i=!0,o=v}finally{try{!n&&a["return"]&&a["return"]()}finally{if(i)throw o}}return e.length&&(e=e.join(") AND (")),{text:e.length?this.options.verb+" ("+e+")":"",values:r}}}]),i}(f.Block),f.WhereBlock=function(n){function o(e){return r(this,o),t(this,(o.__proto__||Object.getPrototypeOf(o)).call(this,i({},e,{verb:"WHERE"})))}return e(o,n),v(o,[{key:"where",value:function(t){for(var e=arguments.length,r=Array(e>1?e-1:0),n=1;n<e;n++)r[n-1]=arguments[n];this._condition.apply(this,[t].concat(r))}}]),o}(f.AbstractConditionBlock),f.HavingBlock=function(n){function o(e){return r(this,o),t(this,(o.__proto__||Object.getPrototypeOf(o)).call(this,i({},e,{verb:"HAVING"})))}return e(o,n),v(o,[{key:"having",value:function(t){for(var e=arguments.length,r=Array(e>1?e-1:0),n=1;n<e;n++)r[n-1]=arguments[n];this._condition.apply(this,[t].concat(r))}}]),o}(f.AbstractConditionBlock),f.OrderByBlock=function(i){function o(e){r(this,o);var n=t(this,(o.__proto__||Object.getPrototypeOf(o)).call(this,e));return n._orders=[],n}return e(o,i),v(o,[{key:"order",value:function(t,e){t=this._sanitizeField(t),"string"!=typeof e&&(void 0===e?e="ASC":null!==e&&(e=e?"ASC":"DESC"));for(var r=arguments.length,n=Array(r>2?r-2:0),i=2;i<r;i++)n[i-2]=arguments[i];this._orders.push({field:t,dir:e,values:n||[]})}},{key:"_toParamString",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e="",r=[],i=!0,o=!1,a=void 0;try{for(var u,s=this._orders[Symbol.iterator]();!(i=(u=s.next()).done);i=!0){var c=u.value,f=c.field,h=c.dir,v=c.values;e=n(e,", ");var d=this._buildString(f,v,{buildParameterized:t.buildParameterized});e+=d.text,l(d.values)&&d.values.forEach(function(t){return r.push(t)}),null!==h&&(e+=" "+h)}}catch(_){o=!0,a=_}finally{try{!i&&s["return"]&&s["return"]()}finally{if(o)throw a}}return{text:e.length?"ORDER BY "+e:"",values:r}}}]),o}(f.Block),f.JoinBlock=function(i){function o(e){r(this,o);var n=t(this,(o.__proto__||Object.getPrototypeOf(o)).call(this,e));return n._joins=[],n}return e(o,i),v(o,[{key:"join",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"INNER";t=this._sanitizeTable(t,!0),e=e?this._sanitizeTableAlias(e):e,r=r?this._sanitizeExpression(r):r,this._joins.push({type:n,table:t,alias:e,condition:r})}},{key:"left_join",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;this.join(t,e,r,"LEFT")}},{key:"right_join",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;this.join(t,e,r,"RIGHT")}},{key:"outer_join",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;this.join(t,e,r,"OUTER")}},{key:"left_outer_join",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;this.join(t,e,r,"LEFT OUTER")}},{key:"full_join",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;this.join(t,e,r,"FULL")}},{key:"cross_join",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;this.join(t,e,r,"CROSS")}},{key:"_toParamString",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e="",r=[],i=!0,o=!1,l=void 0;try{for(var a,u=this._joins[Symbol.iterator]();!(i=(a=u.next()).done);i=!0){var s=a.value,c=s.type,h=s.table,v=s.alias,d=s.condition;e=n(e,this.options.separator);var _=void 0;if(f.isSquelBuilder(h)){var p=h._toParamString({buildParameterized:t.buildParameterized,nested:!0});p.values.forEach(function(t){return r.push(t)}),_=p.text}else _=this._formatTableName(h);if(e+=c+" JOIN "+_,v&&(e+=" "+this._formatTableAlias(v)),d){e+=" ON ";var y=void 0;y=f.isSquelBuilder(d)?d._toParamString({buildParameterized:t.buildParameterized}):this._buildString(d,[],{buildParameterized:t.buildParameterized}),e+=this._applyNestingFormatting(y.text),y.values.forEach(function(t){return r.push(t)})}}}catch(g){o=!0,l=g}finally{try{!i&&u["return"]&&u["return"]()}finally{if(o)throw l}}return{text:e,values:r}}}]),o}(f.Block),f.UnionBlock=function(i){function o(e){r(this,o);var n=t(this,(o.__proto__||Object.getPrototypeOf(o)).call(this,e));return n._unions=[],n}return e(o,i),v(o,[{key:"union",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"UNION";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 t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e="",r=[],i=!0,o=!1,l=void 0;try{for(var a,u=this._unions[Symbol.iterator]();!(i=(a=u.next()).done);i=!0){var s=a.value,c=s.type,h=s.table;e=n(e,this.options.separator);var v=void 0;if(h instanceof f.BaseBuilder){var d=h._toParamString({buildParameterized:t.buildParameterized,nested:!0});v=d.text,d.values.forEach(function(t){return r.push(t)})}else e=this._formatTableName(h);e+=c+" "+v}}catch(_){o=!0,l=_}finally{try{!i&&u["return"]&&u["return"]()}finally{if(o)throw l}}return{text:e,values:r}}}]),o}(f.Block),f.QueryBuilder=function(n){function o(e,n){r(this,o);var i=t(this,(o.__proto__||Object.getPrototypeOf(o)).call(this,e));i.blocks=n||[];var l=!0,a=!1,u=void 0;try{for(var s,c=i.blocks[Symbol.iterator]();!(l=(s=c.next()).done);l=!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,r){i[e]=function(){for(var e=arguments.length,n=Array(e),o=0;o<e;o++)n[o]=arguments[o];return r.call.apply(r,[t].concat(n)),i}}(f,v,d)}}}catch(_){a=!0,u=_}finally{try{!l&&c["return"]&&c["return"]()}finally{if(a)throw u}}return i}return e(o,n),v(o,[{key:"registerValueHandler",value:function(t,e){var r=!0,n=!1,i=void 0;try{for(var l,a=this.blocks[Symbol.iterator]();!(r=(l=a.next()).done);r=!0){var u=l.value;u.registerValueHandler(t,e)}}catch(s){n=!0,i=s}finally{try{!r&&a["return"]&&a["return"]()}finally{if(n)throw i}}return h(o.prototype.__proto__||Object.getPrototypeOf(o.prototype),"registerValueHandler",this).call(this,t,e),this}},{key:"updateOptions",value:function(t){this.options=i({},this.options,t);var e=!0,r=!1,n=void 0;try{for(var o,l=this.blocks[Symbol.iterator]();!(e=(o=l.next()).done);e=!0){var a=o.value;a.options=i({},a.options,t)}}catch(u){r=!0,n=u}finally{try{!e&&l["return"]&&l["return"]()}finally{if(r)throw n}}}},{key:"_toParamString",value:function(){var t=this,e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};e=i({},this.options,e);var r=this.blocks.map(function(r){return r._toParamString({buildParameterized:e.buildParameterized,queryBuilder:t})}),n=r.map(function(t){return t.text}),o=r.map(function(t){return t.values}),l=n.filter(function(t){return 0<t.length}).join(e.separator),a=[];if(o.forEach(function(t){return t.forEach(function(t){return a.push(t)})}),!e.nested&&e.numberedParameters){var u=void 0!==e.numberedParametersStartAt?e.numberedParametersStartAt:1,s=e.parameterCharacter.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&");l=l.replace(new RegExp(s,"g"),function(){return""+e.numberedParametersPrefix+u++})}return{text:this._applyNestingFormatting(l,!!e.nested),values:a}}},{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]}}]),o}(f.BaseBuilder),f.Select=function(n){function i(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;return r(this,i),n=n||[new f.StringBlock(e,"SELECT"),new f.FunctionBlock(e),new f.DistinctBlock(e),new f.GetFieldBlock(e),new f.FromTableBlock(e),new f.JoinBlock(e),new f.WhereBlock(e),new f.GroupByBlock(e),new f.HavingBlock(e),new f.OrderByBlock(e),new f.LimitBlock(e),new f.OffsetBlock(e),new f.UnionBlock(e)],t(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,e,n))}return e(i,n),i}(f.QueryBuilder),f.Update=function(n){function i(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;return r(this,i),n=n||[new f.StringBlock(e,"UPDATE"),new f.UpdateTableBlock(e),new f.SetFieldBlock(e),new f.WhereBlock(e),new f.OrderByBlock(e),new f.LimitBlock(e)],t(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,e,n))}return e(i,n),i}(f.QueryBuilder),f.Delete=function(n){function o(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;return r(this,o),n=n||[new f.StringBlock(e,"DELETE"),new f.TargetTableBlock(e),new f.FromTableBlock(i({},e,{singleTable:!0})),new f.JoinBlock(e),new f.WhereBlock(e),new f.OrderByBlock(e),new f.LimitBlock(e)],t(this,(o.__proto__||Object.getPrototypeOf(o)).call(this,e,n))}return e(o,n),o}(f.QueryBuilder),f.Insert=function(n){function i(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;return r(this,i),n=n||[new f.StringBlock(e,"INSERT"),new f.IntoTableBlock(e),new f.InsertFieldValueBlock(e),new f.InsertFieldsFromQueryBlock(e)],t(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,e,n))}return e(i,n),i}(f.QueryBuilder);var p={VERSION:"5.12.0",flavour:c,expr:function(t){return new f.Expression(t)},"case":function(t,e){return new f.Case(t,e)},select:function(t,e){return new f.Select(t,e)},update:function(t,e){return new f.Update(t,e)},insert:function(t,e){return new f.Insert(t,e)},"delete":function(t,e){return new f.Delete(t,e)},str:function(){var t=new f.FunctionBlock;return t["function"].apply(t,arguments),t},rstr:function(){var t=new f.FunctionBlock({rawNesting:!0});return t["function"].apply(t,arguments),t},registerValueHandler:f.registerValueHandler};return p.remove=p["delete"],p.cls=f,p}var h=function p(t,e,r){null===t&&(t=Function.prototype);var n=Object.getOwnPropertyDescriptor(t,e);if(void 0===n){var i=Object.getPrototypeOf(t);return null===i?void 0:p(i,e,r)}if("value"in n)return n.value;var o=n.get;if(void 0!==o)return o.call(r)},v=function(){function t(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,r,n){return r&&t(e.prototype,r),n&&t(e,n),e}}(),d="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},_=f();return _.flavours={},_.useFlavour=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if(!t)return _;if(_.flavours[t]instanceof Function){var e=f(t);return _.flavours[t].call(null,e),e.flavours=_.flavours,e.useFlavour=_.useFlavour,e}throw new Error("Flavour not available: "+t)},_.flavours.mssql=function(o){var l=o.cls;l.DefaultQueryBuilderOptions.replaceSingleQuotes=!0,l.DefaultQueryBuilderOptions.autoQuoteAliasNames=!1,l.DefaultQueryBuilderOptions.numberedParametersPrefix="@",o.registerValueHandler(Date,function(t){return"'"+t.getUTCFullYear()+"-"+(t.getUTCMonth()+1)+"-"+t.getUTCDate()+" "+t.getUTCHours()+":"+t.getUTCMinutes()+":"+t.getUTCSeconds()+"'"}),l.MssqlLimitOffsetTopBlock=function(n){function i(n){r(this,i);var o=t(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,n));o._limits=null,o._offsets=null;var a=function(t){t=this._sanitizeLimitOffset(t),this._parent._limits=t};return o.ParentBlock=function(n){function i(e){r(this,i);var n=t(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,e.options));return n._parent=e,n}return e(i,n),i}(l.Block),o.LimitBlock=function(n){function i(e){r(this,i);var n=t(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,e));return n.limit=a,n}return e(i,n),v(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(n){function i(e){r(this,i);var n=t(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,e));return n.top=a,n}return e(i,n),v(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(n){function i(){return r(this,i),t(this,(i.__proto__||Object.getPrototypeOf(i)).apply(this,arguments))}return e(i,n),v(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 e(i,n),v(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}(l.Block),l.MssqlUpdateTopBlock=function(n){function i(e){r(this,i);var n=t(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,e));return n._limits=null,n.limit=n.top=function(t){n._limits=n._sanitizeLimitOffset(t)},n}return e(i,n),v(i,[{key:"_toParamString",value:function(){return{text:this._limits?"TOP ("+this._limits+")":"",values:[]}}}]),i}(l.Block),l.MssqlInsertFieldValueBlock=function(n){function i(e){r(this,i);var n=t(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,e));return n._outputs=[],n}return e(i,n),v(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=h(i.prototype.__proto__||Object.getPrototypeOf(i.prototype),"_toParamString",this).call(this,t);if(e.text.length&&0<this._outputs.length){var r="OUTPUT "+this._outputs.join(", ")+" ",n=e.text.indexOf("VALUES");e.text=e.text.substr(0,n)+r+e.text.substr(n)}return e}}]),i}(l.InsertFieldValueBlock),l.MssqlUpdateDeleteOutputBlock=function(i){function o(e){r(this,o);var n=t(this,(o.__proto__||Object.getPrototypeOf(o)).call(this,e));return n._outputs=[],n}return e(o,i),v(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]?arguments[1]:null;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 r=!0,i=!1,o=void 0;try{for(var l,a=this._outputs[Symbol.iterator]();!(r=(l=a.next()).done);r=!0){var u=l.value;e=n(e,", "),e+=u.name,u.alias&&(e+=" AS "+this._formatFieldAlias(u.alias))}}catch(s){i=!0,o=s}finally{try{!r&&a["return"]&&a["return"]()}finally{if(i)throw o}}e="OUTPUT "+e}return{text:e,values:[]}}}]),o}(l.Block),l.Select=function(n){function i(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;r(this,i);var o=new l.MssqlLimitOffsetTopBlock(e);return n=n||[new l.StringBlock(e,"SELECT"),new l.DistinctBlock(e),o.TOP(),new l.GetFieldBlock(e),new l.FromTableBlock(e),new l.JoinBlock(e),new l.WhereBlock(e),new l.GroupByBlock(e),new l.OrderByBlock(e),o.OFFSET(),o.LIMIT(),new l.UnionBlock(e)],t(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,e,n))}return e(i,n),i}(l.QueryBuilder),l.Update=function(n){function i(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;return r(this,i),n=n||[new l.StringBlock(e,"UPDATE"),new l.MssqlUpdateTopBlock(e),new l.UpdateTableBlock(e),new l.SetFieldBlock(e),new l.MssqlUpdateDeleteOutputBlock(e),new l.WhereBlock(e)],t(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,e,n))}return e(i,n),i}(l.QueryBuilder),l.Delete=function(n){function o(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;return r(this,o),n=n||[new l.StringBlock(e,"DELETE"),new l.TargetTableBlock(e),new l.FromTableBlock(i({},e,{singleTable:!0})),new l.JoinBlock(e),new l.MssqlUpdateDeleteOutputBlock(i({},e,{forDelete:!0})),new l.WhereBlock(e),new l.OrderByBlock(e),new l.LimitBlock(e)],t(this,(o.__proto__||Object.getPrototypeOf(o)).call(this,e,n))}return e(o,n),o}(l.QueryBuilder),l.Insert=function(n){function i(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;return r(this,i),n=n||[new l.StringBlock(e,"INSERT"),new l.IntoTableBlock(e),new l.MssqlInsertFieldValueBlock(e),new l.InsertFieldsFromQueryBlock(e)],t(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,e,n))}return e(i,n),i}(l.QueryBuilder)},_.flavours.mysql=function(i){var o=i.cls;o.MysqlOnDuplicateKeyUpdateBlock=function(i){function o(){return r(this,o),t(this,(o.__proto__||Object.getPrototypeOf(o)).apply(this,arguments))}return e(o,i),v(o,[{key:"onDupUpdate",value:function(t,e,r){this._set(t,e,r)}},{key:"_toParamString",value:function(){for(var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e="",r=[],i=0;i<this._fields.length;++i){e=n(e,", ");var o=this._fields[i],l=this._values[0][i],a=this._valueOptions[0][i];if("undefined"==typeof l)e+=o;else{var u=this._buildString(o+" = "+this.options.parameterCharacter,[l],{buildParameterized:t.buildParameterized,formattingOptions:a});e+=u.text,u.values.forEach(function(t){return r.push(t)})}}return{text:e.length?"ON DUPLICATE KEY UPDATE "+e:"",values:r}}}]),o}(o.AbstractSetFieldBlock),o.Insert=function(n){function i(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;return r(this,i),n=n||[new o.StringBlock(e,"INSERT"),new o.IntoTableBlock(e),new o.InsertFieldValueBlock(e),new o.InsertFieldsFromQueryBlock(e),new o.MysqlOnDuplicateKeyUpdateBlock(e)],t(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,e,n))}return e(i,n),i}(o.QueryBuilder),o.Replace=function(n){function i(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;return r(this,i),n=n||[new o.StringBlock(e,"REPLACE"),new o.IntoTableBlock(e),new o.InsertFieldValueBlock(e),new o.InsertFieldsFromQueryBlock(e)],t(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,e,n))}return e(i,n),i}(o.QueryBuilder),i.replace=function(t,e){return new o.Replace(t,e)}},_.flavours.postgres=function(o){var a=o.cls;a.DefaultQueryBuilderOptions.numberedParameters=!0,a.DefaultQueryBuilderOptions.numberedParametersStartAt=1,a.DefaultQueryBuilderOptions.autoQuoteAliasNames=!1,a.DefaultQueryBuilderOptions.useAsForTableAliasNames=!0,a.PostgresOnConflictKeyUpdateBlock=function(i){function o(){return r(this,o),t(this,(o.__proto__||Object.getPrototypeOf(o)).apply(this,arguments))}return e(o,i),v(o,[{key:"onConflict",value:function(t,e){var r=this;this._onConflict=!0,t&&(l(t)||(t=[t]),this._dupFields=t.map(this._sanitizeField.bind(this)),e&&Object.keys(e).forEach(function(t){r._set(t,e[t])}))}},{key:"_toParamString",value:function(){for(var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e="",r=[],i=0;i<this._fields.length;++i){e=n(e,", ");var o=this._fields[i],l=this._values[0][i],a=this._valueOptions[0][i];if("undefined"==typeof l)e+=o;else{var u=this._buildString(o+" = "+this.options.parameterCharacter,[l],{buildParameterized:t.buildParameterized,formattingOptions:a});e+=u.text,u.values.forEach(function(t){return r.push(t)})}}var s={text:"",values:r};if(this._onConflict){var c=this._dupFields?"("+this._dupFields.join(", ")+") ":"",f=e.length?"UPDATE SET "+e:"NOTHING";s.text="ON CONFLICT "+c+"DO "+f}return s}}]),o}(a.AbstractSetFieldBlock),a.ReturningBlock=function(i){function o(e){r(this,o);var n=t(this,(o.__proto__||Object.getPrototypeOf(o)).call(this,e));return n._fields=[],n}return e(o,i),v(o,[{key:"returning",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};e=e?this._sanitizeFieldAlias(e):e,t=this._sanitizeField(t);var n=this._fields.filter(function(r){return r.name===t&&r.alias===e});return n.length?this:void this._fields.push({name:t,alias:e,options:r})}},{key:"_toParamString",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=(t.queryBuilder,t.buildParameterized),r="",i=[],o=!0,l=!1,a=void 0;try{for(var u,s=this._fields[Symbol.iterator]();!(o=(u=s.next()).done);o=!0){var c=u.value;r=n(r,", ");var f=c.name,h=c.alias,v=c.options;if("string"==typeof f)r+=this._formatFieldName(f,v);else{var d=f._toParamString({nested:!0,buildParameterized:e});r+=d.text,d.values.forEach(function(t){return i.push(t)})}h&&(r+=" AS "+this._formatFieldAlias(h))}}catch(_){l=!0,a=_}finally{try{!o&&s["return"]&&s["return"]()}finally{if(l)throw a}}return{text:r.length>0?"RETURNING "+r:"",values:i}}}]),o}(a.Block),a.WithBlock=function(n){function i(e){r(this,i);var n=t(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,e));return n._tables=[],n}return e(i,n),v(i,[{key:"with",value:function(t,e){this._tables.push({alias:t,table:e})}},{key:"_toParamString",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=[],r=[],n=!0,i=!1,o=void 0;try{for(var l,a=this._tables[Symbol.iterator]();!(n=(l=a.next()).done);n=!0){var u=l.value,s=u.alias,c=u.table,f=c._toParamString({buildParameterized:t.buildParameterized,nested:!0});e.push(s+" AS "+f.text),f.values.forEach(function(t){return r.push(t)})}}catch(h){i=!0,o=h}finally{try{!n&&a["return"]&&a["return"]()}finally{if(i)throw o}}return{text:e.length?"WITH "+e.join(", "):"",values:r}}}]),i}(a.Block),a.DistinctOnBlock=function(n){function i(e){r(this,i);var n=t(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,e));return n._distinctFields=[],n}return e(i,n),v(i,[{key:"distinct",value:function(){var t=this;this._useDistinct=!0;for(var e=arguments.length,r=Array(e),n=0;n<e;n++)r[n]=arguments[n];r.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(n){function i(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;return r(this,i),n=n||[new a.WithBlock(e),new a.StringBlock(e,"SELECT"),new a.FunctionBlock(e),new a.DistinctOnBlock(e),new a.GetFieldBlock(e),new a.FromTableBlock(e),new a.JoinBlock(e),new a.WhereBlock(e),new a.GroupByBlock(e),new a.HavingBlock(e),new a.OrderByBlock(e),new a.LimitBlock(e),new a.OffsetBlock(e),new a.UnionBlock(e)],t(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,e,n))}return e(i,n),i}(a.QueryBuilder),a.Insert=function(n){function i(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;return r(this,i),n=n||[new a.WithBlock(e),new a.StringBlock(e,"INSERT"),new a.IntoTableBlock(e),new a.InsertFieldValueBlock(e),new a.InsertFieldsFromQueryBlock(e),new a.PostgresOnConflictKeyUpdateBlock(e),new a.ReturningBlock(e)],t(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,e,n))}return e(i,n),i}(a.QueryBuilder),a.Update=function(n){function i(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;return r(this,i),n=n||[new a.WithBlock(e),new a.StringBlock(e,"UPDATE"),new a.UpdateTableBlock(e),new a.SetFieldBlock(e),new a.FromTableBlock(e),new a.WhereBlock(e),new a.OrderByBlock(e),new a.LimitBlock(e),new a.ReturningBlock(e)],t(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,e,n))}return e(i,n),i}(a.QueryBuilder),a.Delete=function(n){function o(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;return r(this,o),n=n||[new a.WithBlock(e),new a.StringBlock(e,"DELETE"),new a.TargetTableBlock(e),new a.FromTableBlock(i({},e,{singleTable:!0})),new a.JoinBlock(e),new a.WhereBlock(e),new a.OrderByBlock(e),new a.LimitBlock(e),new a.ReturningBlock(e)],t(this,(o.__proto__||Object.getPrototypeOf(o)).call(this,e,n))}return e(o,n),o}(a.QueryBuilder)},_});
{
"name": "squel",
"description": "SQL query string builder",
"version": "5.11.1",
"version": "5.12.0",
"author": "Ramesh Nair <ram@hiddentao.com> (http://www.hiddentao.com/)",

@@ -6,0 +6,0 @@ "contributors": [

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc