forked from hiddentao/squel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
squel.min.js
2 lines (2 loc) · 42.3 KB
/
squel.min.js
1
2
/*! squel | https://github.com/hiddentao/squel | BSD license */!function(t,e){"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?module.exports=e():t.squel=e()}(this,function(){"use strict";function t(t){if(Array.isArray(t)){for(var e=0,r=Array(t.length);e<t.length;e++)r[e]=t[e];return r}return Array.from(t)}function e(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function r(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 i(t,e){return t.length?t+e:t}function o(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,o=!1,a=void 0;try{for(var l,u=function(){var e=l.value;"object"===("undefined"==typeof e?"undefined":y(e))&&Object.getOwnPropertyNames(e).forEach(function(r){"function"!=typeof e[r]&&(t[r]=e[r])})},s=r[Symbol.iterator]();!(i=(l=s.next()).done);i=!0)u()}catch(c){o=!0,a=c}finally{try{!i&&s["return"]&&s["return"]()}finally{if(o)throw a}}}return t}function a(t){return t&&t.constructor.prototype===Object.prototype}function l(t){return t&&t.constructor.prototype===Array.prototype}function u(t){if(t&&t.constructor&&t.constructor.toString){var e=t.constructor.toString().match(/function\s*(\w+)/);if(e&&2===e.length)return e[1]}}function s(t){if(!t)return t;if("function"==typeof t.clone)return t.clone();if(!a(t)&&!l(t))return JSON.parse(JSON.stringify(t));var e=function(){var e=new t.constructor;return Object.getOwnPropertyNames(t).forEach(function(r){"function"!=typeof t[r]&&(e[r]=s(t[r]))}),{v:e}}();return"object"===("undefined"==typeof e?"undefined":y(e))?e.v:void 0}function c(t,e,r){var n="undefined"==typeof e?"undefined":y(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(c){o=!0,a=c}finally{try{!i&&u["return"]&&u["return"]()}finally{if(o)throw a}}t.push({type:e,handler:r})}function f(t){for(var e=arguments.length,r=Array(e>1?e-1:0),n=1;e>n;n++)r[n-1]=arguments[n];var i=!0,o=!1,a=void 0;try{for(var l,u=r[Symbol.iterator]();!(i=(l=u.next()).done);i=!0){var s=l.value,c=!0,f=!1,h=void 0;try{for(var v,d=s[Symbol.iterator]();!(c=(v=d.next()).done);c=!0){var p=v.value;if(("undefined"==typeof t?"undefined":y(t))===p.type||"string"!=typeof p.type&&t instanceof p.type)return p.handler}}catch(g){f=!0,h=g}finally{try{!c&&d["return"]&&d["return"]()}finally{if(f)throw h}}}}catch(g){o=!0,a=g}finally{try{!i&&u["return"]&&u["return"]()}finally{if(o)throw a}}}function h(){var h=arguments.length<=0||void 0===arguments[0]?null:arguments[0],p={_getObjectClassName:u};p.DefaultQueryBuilderOptions={autoQuoteTableNames:!1,autoQuoteFieldNames:!1,autoQuoteAliasNames:!0,useAsForTableAliasNames:!1,nameQuoteCharacter:"`",tableAliasQuoteCharacter:"`",fieldAliasQuoteCharacter:'"',valueHandlers:[],parameterCharacter:"?",numberedParameters:!1,numberedParametersPrefix:"$",numberedParametersStartAt:1,replaceSingleQuotes:!1,singleQuoteReplacement:"''",separator:" "},p.globalValueHandlers=[],p.registerValueHandler=function(t,e){c(p.globalValueHandlers,t,e)},p.Cloneable=function(){function t(){n(this,t)}return d(t,[{key:"clone",value:function(){var t=new this.constructor;return o(t,s(o({},this)))}}]),t}(),p.BaseBuilder=function(i){function a(t){n(this,a);var r=e(this,Object.getPrototypeOf(a).call(this)),i=JSON.parse(JSON.stringify(p.DefaultQueryBuilderOptions));return r.options=o({},i,t),r}return r(a,i),d(a,[{key:"registerValueHandler",value:function(t,e){return c(this.options.valueHandlers,t,e),this}},{key:"_sanitizeExpression",value:function(t){if(!(t instanceof p.Expression)&&"string"!=typeof t)throw new Error("expression must be a string or Expression instance");return t}},{key:"_sanitizeName",value:function(t,e){if("string"!=typeof t)throw new Error(e+" must be a string");return t}},{key:"_sanitizeField",value:function(t){return t instanceof p.BaseBuilder||(t=this._sanitizeName(t,"field name")),t}},{key:"_sanitizeQueryBuilder",value:function(t){if(t instanceof p.QueryBuilder)return t;throw new Error("must be a QueryBuilder instance")}},{key:"_sanitizeTable",value:function(t){if("string"!=typeof t)try{t=this._sanitizeQueryBuilder(t)}catch(e){throw new Error("table name must be a string or a query builder")}else t=this._sanitizeName(t,"table");return t}},{key:"_sanitizeTableAlias",value:function(t){return this._sanitizeName(t,"table alias")}},{key:"_sanitizeFieldAlias",value:function(t){return this._sanitizeName(t,"field alias")}},{key:"_sanitizeLimitOffset",value:function(t){if(t=parseInt(t),0>t||isNaN(t))throw new Error("limit/offset must be >= 0");return t}},{key:"_sanitizeValue",value:function(t){var e="undefined"==typeof t?"undefined":y(t);if(null===t);else if("string"===e||"number"===e||"boolean"===e);else if(t instanceof p.BaseBuilder);else{var r=!!f(t,this.options.valueHandlers,p.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){var e=arguments.length<=1||void 0===arguments[1]?!1:arguments[1],r=f(t,this.options.valueHandlers,p.globalValueHandlers);return r&&(t=r(t,e)),t}},{key:"_formatValueForParamArray",value:function(t){var e=this;return l(t)?t.map(function(t){return e._formatValueForParamArray(t)}):this._formatCustomValue(t,!0)}},{key:"_formatValueForQueryString",value:function(t){var e=this,r=arguments.length<=1||void 0===arguments[1]?{}:arguments[1],n=this._formatCustomValue(t);if(n!==t)return this._applyNestingFormatting(n);if(l(t))t=t.map(function(t){return e._formatValueForQueryString(t)}),t=this._applyNestingFormatting(t.join(", "));else{var i="undefined"==typeof t?"undefined":y(t);if(null===t)t="NULL";else if("boolean"===i)t=t?"TRUE":"FALSE";else if(t instanceof p.BaseBuilder)t=this._applyNestingFormatting(t.toString());else if("number"!==i)if(r.dontQuote)t=""+t;else{var o=this._escapeValue(t);t="'"+o+"'"}}return t}},{key:"_applyNestingFormatting",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?!0:arguments[1];return t&&"string"==typeof t&&e&&("("!==t.charAt(0)||")"!==t.charAt(t.length-1))?"("+t+")":t}},{key:"_buildString",value:function(e,r){var n=arguments.length<=2||void 0===arguments[2]?{}:arguments[2],i=n.nested,o=n.buildParameterized,a=n.formattingOptions;r=r||[],e=e||"";for(var u="",s=-1,c=[],f=this.options.parameterCharacter,h=0;e.length>h;)if(e.substr(h,f.length)===f){var v=r[++s];if(o)if(v instanceof p.BaseBuilder){var d=v._toParamString({buildParameterized:o,nested:!0});u+=d.text,c.push.apply(c,t(d.values))}else if(v=this._formatValueForParamArray(v),l(v)){var y=v.map(function(){return f}).join(", ");u+="("+y+")",c.push.apply(c,t(v))}else u+=f,c.push(v);else u+=this._formatValueForQueryString(v,a);h+=f.length}else u+=e.charAt(h),h++;return{text:this._applyNestingFormatting(u,!!i),values:c}}},{key:"_buildManyStrings",value:function(e,r){for(var n=arguments.length<=2||void 0===arguments[2]?{}:arguments[2],i=[],o=[],a=0;e.length>a;++a){var l=e[a],u=r[a],s=this._buildString(l,u,{buildParameterized:n.buildParameterized,nested:!1}),c=s.text,f=s.values;i.push(c),o.push.apply(o,t(f))}return i=i.join(this.options.separator),{text:i.length?this._applyNestingFormatting(i,!!n.nested):"",values:o}}},{key:"_toParamString",value:function(t){throw new Error("Not yet implemented")}},{key:"toString",value:function(){var t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];return this._toParamString(t).text}},{key:"toParam",value:function(){var t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];return this._toParamString(o({},t,{buildParameterized:!0}))}}]),a}(p.Cloneable),p.Expression=function(i){function o(t){n(this,o);var r=e(this,Object.getPrototypeOf(o).call(this,t));return r._nodes=[],r}return r(o,i),d(o,[{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 e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],r=[],n=[],i=!0,o=!1,a=void 0;try{for(var l,u=this._nodes[Symbol.iterator]();!(i=(l=u.next()).done);i=!0){var s=l.value,c=s.type,f=s.expr,h=s.para,v=f instanceof p.Expression?f._toParamString({buildParameterized:e.buildParameterized,nested:!0}):this._buildString(f,h,{buildParameterized:e.buildParameterized}),d=v.text,y=v.values;r.length&&r.push(c),r.push(d),n.push.apply(n,t(y))}}catch(g){o=!0,a=g}finally{try{!i&&u["return"]&&u["return"]()}finally{if(o)throw a}}return r=r.join(" "),{text:this._applyNestingFormatting(r,!!e.nested),values:n}}}]),o}(p.BaseBuilder),p.Case=function(l){function u(t){var r=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];n(this,u);var i=e(this,Object.getPrototypeOf(u).call(this,r));return a(t)&&(r=t,t=null),t&&(i._fieldName=i._sanitizeField(t)),i.options=o({},p.DefaultQueryBuilderOptions,r),i._cases=[],i._elseValue=null,i}return r(u,l),d(u,[{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 e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],r="",n=[],o=!0,a=!1,l=void 0;try{for(var u,s=this._cases[Symbol.iterator]();!(o=(u=s.next()).done);o=!0){var c=u.value,f=c.expression,h=c.values,v=c.result;r=i(r," ");var d=this._buildString(f,h,{buildParameterized:e.buildParameterized,nested:!0});r+="WHEN "+d.text+" THEN "+this._formatValueForQueryString(v),n.push.apply(n,t(d.values))}}catch(y){a=!0,l=y}finally{try{!o&&s["return"]&&s["return"]()}finally{if(a)throw l}}return r.length?(r+=" ELSE "+this._formatValueForQueryString(this._elseValue)+" END",this._fieldName&&(r=this._fieldName+" "+r),r="CASE "+r):r=this._formatValueForQueryString(this._elseValue),{text:r,values:n}}}]),u}(p.BaseBuilder),p.Block=function(t){function i(t){return n(this,i),e(this,Object.getPrototypeOf(i).call(this,t))}return r(i,t),d(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)||p.Block.prototype[r]||(t[r]=e[r])}),e=Object.getPrototypeOf(e);return t}}]),i}(p.BaseBuilder),p.StringBlock=function(t){function i(t,r){n(this,i);var o=e(this,Object.getPrototypeOf(i).call(this,t));return o._str=r,o}return r(i,t),d(i,[{key:"_toParamString",value:function(){arguments.length<=0||void 0===arguments[0]?{}:arguments[0];return{text:this._str,values:[]}}}]),i}(p.Block),p.FunctionBlock=function(t){function i(t){n(this,i);var r=e(this,Object.getPrototypeOf(i).call(this,t));return r._strings=[],r._values=[],r}return r(i,t),d(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}(p.Block),p.registerValueHandler(p.FunctionBlock,function(t){var e=arguments.length<=1||void 0===arguments[1]?!1:arguments[1];return e?t.toParam():t.toString()}),p.AbstractTableBlock=function(o){function a(t,r){n(this,a);var i=e(this,Object.getPrototypeOf(a).call(this,t));return i._tables=[],i}return r(a,o),d(a,[{key:"_table",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?null:arguments[1];e=e?this._sanitizeTableAlias(e):e,t=this._sanitizeTable(t),this.options.singleTable&&(this._tables=[]),this._tables.push({table:t,alias:e})}},{key:"_hasTable",value:function(){return 0<this._tables.length}},{key:"_toParamString",value:function(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],r="",n=[];if(this._hasTable()){var o=!0,a=!1,l=void 0;try{for(var u,s=this._tables[Symbol.iterator]();!(o=(u=s.next()).done);o=!0){var c=u.value,f=c.table,h=c.alias;r=i(r,", ");var v=f;if(f instanceof p.BaseBuilder){var d=f._toParamString({buildParameterized:e.buildParameterized,nested:!0}),y=d.text,g=d.values;v=y,n.push.apply(n,t(g))}h&&(v+=" "+this._formatTableAlias(h)),r+=v}}catch(_){a=!0,l=_}finally{try{!o&&s["return"]&&s["return"]()}finally{if(a)throw l}}this.options.prefix&&(r=this.options.prefix+" "+r)}return{text:r,values:n}}}]),a}(p.Block),p.UpdateTableBlock=function(t){function i(){return n(this,i),e(this,Object.getPrototypeOf(i).apply(this,arguments))}return r(i,t),d(i,[{key:"table",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?null:arguments[1];this._table(t,e)}},{key:"_toParamString",value:function(){var t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];if(!this._hasTable())throw new Error("table() needs to be called");return v(Object.getPrototypeOf(i.prototype),"_toParamString",this).call(this,t)}}]),i}(p.AbstractTableBlock),p.FromTableBlock=function(t){function i(t){return n(this,i),e(this,Object.getPrototypeOf(i).call(this,o({},t,{prefix:"FROM"})))}return r(i,t),d(i,[{key:"from",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?null:arguments[1];this._table(t,e)}},{key:"_toParamString",value:function(){var t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];return v(Object.getPrototypeOf(i.prototype),"_toParamString",this).call(this,t)}}]),i}(p.AbstractTableBlock),p.IntoTableBlock=function(t){function i(t){return n(this,i),e(this,Object.getPrototypeOf(i).call(this,o({},t,{prefix:"INTO",singleTable:!0})))}return r(i,t),d(i,[{key:"into",value:function(t){this._table(t)}},{key:"_toParamString",value:function(){var t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];if(!this._hasTable())throw new Error("into() needs to be called");return v(Object.getPrototypeOf(i.prototype),"_toParamString",this).call(this,t)}}]),i}(p.AbstractTableBlock),p.GetFieldBlock=function(o){function a(t){n(this,a);var r=e(this,Object.getPrototypeOf(a).call(this,t));return r._fields=[],r}return r(a,o),d(a,[{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]?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 e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],r=e.queryBuilder,n=e.buildParameterized,o="",a=[],l=!0,u=!1,s=void 0;try{for(var c,f=this._fields[Symbol.iterator]();!(l=(c=f.next()).done);l=!0){var h=c.value;o=i(o,", ");var v=h.name,d=h.alias,y=h.options;if("string"==typeof v)o+=this._formatFieldName(v,y);else{var g=v._toParamString({nested:!0,buildParameterized:n});o+=g.text,a.push.apply(a,t(g.values))}d&&(o+=" AS "+this._formatFieldAlias(d))}}catch(_){u=!0,s=_}finally{try{!l&&f["return"]&&f["return"]()}finally{if(u)throw s}}if(!o.length){var m=r&&r.getBlock(p.FromTableBlock);m&&m._hasTable()&&(o="*")}return{text:o,values:a}}}]),a}(p.Block),p.AbstractSetFieldBlock=function(t){function i(t){n(this,i);var r=e(this,Object.getPrototypeOf(i).call(this,t));return r._reset(),r}return r(i,t),d(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":y(t)))throw new Error("Expected an object but got "+("undefined"==typeof t?"undefined":y(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":y(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(r>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[r])||(this._values[r]=[],this._valueOptions[r]=[]),this._values[r][a]=o,this._valueOptions[r][a]=e}}}}]),i}(p.Block),p.SetFieldBlock=function(o){function a(){return n(this,a),e(this,Object.getPrototypeOf(a).apply(this,arguments))}return r(a,o),d(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 e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],r=e.buildParameterized;if(0>=this._fields.length)throw new Error("set() needs to be called");for(var n="",o=[],a=0;a<this._fields.length;++a){n=i(n,", ");var l=this._formatFieldName(this._fields[a]),u=this._values[0][a];if("undefined"==typeof u)n+=l;else{var s=this._buildString(l+" = "+this.options.parameterCharacter,[u],{buildParameterized:r,formattingOptions:this._valueOptions[0][a]});n+=s.text,o.push.apply(o,t(s.values))}}return{text:"SET "+n,values:o}}}]),a}(p.AbstractSetFieldBlock),p.InsertFieldValueBlock=function(o){function a(){return n(this,a),e(this,Object.getPrototypeOf(a).apply(this,arguments))}return r(a,o),d(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 e=this,r=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],n=r.buildParameterized,o=this._fields.map(function(t){return e._formatFieldName(t)}).join(", "),a=[],l=[],u=0;u<this._values.length;++u){a[u]="";for(var s=0;s<this._values[u].length;++s){var c=this._buildString(this.options.parameterCharacter,[this._values[u][s]],{buildParameterized:n,formattingOptions:this._valueOptions[u][s]});l.push.apply(l,t(c.values)),a[u]=i(a[u],", "),a[u]+=c.text}}return{text:o.length?"("+o+") VALUES ("+a.join("), (")+")":"",values:l}}}]),a}(p.AbstractSetFieldBlock),p.InsertFieldsFromQueryBlock=function(t){function i(t){n(this,i);var r=e(this,Object.getPrototypeOf(i).call(this,t));return r._fields=[],r._query=null,r}return r(i,t),d(i,[{key:"fromQuery",value:function(t,e){var r=this;this._fields=t.map(function(t){return r._sanitizeField(t)}),this._query=this._sanitizeQueryBuilder(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(", ")+") ("+i+")",r=o}return{text:e,values:r}}}]),i}(p.Block),p.DistinctBlock=function(t){function i(){return n(this,i),e(this,Object.getPrototypeOf(i).apply(this,arguments))}return r(i,t),d(i,[{key:"distinct",value:function(){this._useDistinct=!0}},{key:"_toParamString",value:function(){return{text:this._useDistinct?"DISTINCT":"",values:[]}}}]),i}(p.Block),p.GroupByBlock=function(t){function i(t){n(this,i);var r=e(this,Object.getPrototypeOf(i).call(this,t));return r._groups=[],r}return r(i,t),d(i,[{key:"group",value:function(t){this._groups.push(this._sanitizeField(t))}},{key:"_toParamString",value:function(){arguments.length<=0||void 0===arguments[0]?{}:arguments[0];return{text:this._groups.length?"GROUP BY "+this._groups.join(", "):"",values:[]}}}]),i}(p.Block),p.OffsetBlock=function(t){function i(t){n(this,i);var r=e(this,Object.getPrototypeOf(i).call(this,t));return r._offsets=null,r}return r(i,t),d(i,[{key:"offset",value:function(t){this._offsets=this._sanitizeLimitOffset(t)}},{key:"_toParamString",value:function(){return{text:this._offsets?"OFFSET "+this._offsets:"",values:[]}}}]),i}(p.Block),p.AbstractConditionBlock=function(i){function o(t){n(this,o);var r=e(this,Object.getPrototypeOf(o).call(this,t));return r._conditions=[],r}return r(o,i),d(o,[{key:"_condition",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];t=this._sanitizeExpression(t),this._conditions.push({expr:t,values:r})}},{key:"_toParamString",value:function(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],r=[],n=[],i=!0,o=!1,a=void 0;try{for(var l,u=this._conditions[Symbol.iterator]();!(i=(l=u.next()).done);i=!0){var s=l.value,c=s.expr,f=s.values,h=c instanceof p.Expression?c._toParamString({buildParameterized:e.buildParameterized}):this._buildString(c,f,{buildParameterized:e.buildParameterized});h.text.length&&r.push(h.text),n.push.apply(n,t(h.values))}}catch(v){o=!0,a=v}finally{try{!i&&u["return"]&&u["return"]()}finally{if(o)throw a}}return r.length&&(r=r.join(") AND (")),{text:r.length?this.options.verb+" ("+r+")":"",values:n}}}]),o}(p.Block),p.WhereBlock=function(t){function i(t){return n(this,i),e(this,Object.getPrototypeOf(i).call(this,o({},t,{verb:"WHERE"})))}return r(i,t),d(i,[{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))}}]),i}(p.AbstractConditionBlock),p.HavingBlock=function(t){function i(t){return n(this,i),e(this,Object.getPrototypeOf(i).call(this,o({},t,{verb:"HAVING"})))}return r(i,t),d(i,[{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))}}]),i}(p.AbstractConditionBlock),p.OrderByBlock=function(o){function a(t){n(this,a);var r=e(this,Object.getPrototypeOf(a).call(this,t));return r._orders=[],r}return r(a,o),d(a,[{key:"order",value:function(t,e){for(var r=arguments.length,n=Array(r>2?r-2:0),i=2;r>i;i++)n[i-2]=arguments[i];t=this._sanitizeField(t),e=void 0===e?!0:e,e=null!==e?!!e:e,this._orders.push({field:t,dir:e,values:n})}},{key:"_toParamString",value:function(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],r="",n=[],o=!0,a=!1,l=void 0;try{for(var u,s=this._orders[Symbol.iterator]();!(o=(u=s.next()).done);o=!0){var c=u.value,f=c.field,h=c.dir,v=c.values;r=i(r,", ");var d=this._buildString(f,v,{buildParameterized:e.buildParameterized});r+=d.text,n.push.apply(n,t(d.values)),null!==h&&(r+=" "+(h?"ASC":"DESC"))}}catch(y){a=!0,l=y}finally{try{!o&&s["return"]&&s["return"]()}finally{if(a)throw l}}return{text:r.length?"ORDER BY "+r:"",values:n}}}]),a}(p.Block),p.LimitBlock=function(t){function i(t){n(this,i);var r=e(this,Object.getPrototypeOf(i).call(this,t));return r._limit=null,r}return r(i,t),d(i,[{key:"limit",value:function(t){this._limit=this._sanitizeLimitOffset(t)}},{key:"_toParamString",value:function(){return{text:null!==this._limit?"LIMIT "+this._limit:"",values:[]}}}]),i}(p.Block),p.JoinBlock=function(o){function a(t){n(this,a);var r=e(this,Object.getPrototypeOf(a).call(this,t));return r._joins=[],r}return r(a,o),d(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 e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],r="",n=[],o=!0,a=!1,l=void 0;try{for(var u,s=this._joins[Symbol.iterator]();!(o=(u=s.next()).done);o=!0){var c=u.value,f=c.type,h=c.table,v=c.alias,d=c.condition;r=i(r,this.options.separator);var y=void 0;if(h instanceof p.BaseBuilder){var g=h._toParamString({buildParameterized:e.buildParameterized,nested:!0});n.push.apply(n,t(g.values)),y=g.text}else y=this._formatTableName(h);if(r+=f+" JOIN "+y,v&&(r+=" "+this._formatTableAlias(v)),d){r+=" ON ";var _=void 0;_=d instanceof p.Expression?d._toParamString({buildParameterized:e.buildParameterized}):this._buildString(d,[],{buildParameterized:e.buildParameterized}),r+=this._applyNestingFormatting(_.text),n.push.apply(n,t(_.values))}}}catch(m){a=!0,l=m}finally{try{!o&&s["return"]&&s["return"]()}finally{if(a)throw l}}return{text:r,values:n}}}]),a}(p.Block),p.UnionBlock=function(o){function a(t){n(this,a);var r=e(this,Object.getPrototypeOf(a).call(this,t));return r._unions=[],r}return r(a,o),d(a,[{key:"union",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?"UNION":arguments[1];t=this._sanitizeTable(t),this._unions.push({type:e,table:t})}},{key:"union_all",value:function(t){this.union(t,"UNION ALL")}},{key:"_toParamString",value:function(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],r="",n=[],o=!0,a=!1,l=void 0;try{for(var u,s=this._unions[Symbol.iterator]();!(o=(u=s.next()).done);o=!0){var c=u.value,f=c.type,h=c.table;r=i(r,this.options.separator);var v=void 0;if(h instanceof p.BaseBuilder){var d=h._toParamString({buildParameterized:e.buildParameterized,nested:!0});v=d.text,n.push.apply(n,t(d.values))}else r=this._formatTableName(h);r+=f+" "+v}}catch(y){a=!0,l=y}finally{try{!o&&s["return"]&&s["return"]()}finally{if(a)throw l}}return{text:r,values:n}}}]),a}(p.Block),p.QueryBuilder=function(i){function a(t,r){n(this,a);var i=e(this,Object.getPrototypeOf(a).call(this,t));i.blocks=r||[];var o=!0,l=!1,u=void 0;try{for(var s,c=i.blocks[Symbol.iterator]();!(o=(s=c.next()).done);o=!0){var f=s.value,h=f.exposedMethods();for(var v in h){var d=h[v];if(void 0!==i[v])throw new Error("Builder already has a builder method called: "+v);!function(t,e,r){i[e]=function(){for(var e=arguments.length,n=Array(e),o=0;e>o;o++)n[o]=arguments[o];return r.call.apply(r,[t].concat(n)),i}}(f,v,d)}}}catch(y){l=!0,u=y}finally{try{!o&&c["return"]&&c["return"]()}finally{if(l)throw u}}return i}return r(a,i),d(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 v(Object.getPrototypeOf(a.prototype),"registerValueHandler",this).call(this,t,e),this}},{key:"updateOptions",value:function(t){this.options=o({},this.options,t);var e=!0,r=!1,n=void 0;try{for(var i,a=this.blocks[Symbol.iterator]();!(e=(i=a.next()).done);e=!0){var l=i.value;l.options=o({},l.options,t)}}catch(u){r=!0,n=u}finally{try{!e&&a["return"]&&a["return"]()}finally{if(r)throw n}}}},{key:"_toParamString",value:function(){var e,r=this,n=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];n=o({},this.options,n);var i=this.blocks.map(function(t){return t._toParamString({buildParameterized:n.buildParameterized,queryBuilder:r})}),a=i.map(function(t){return t.text}),l=i.map(function(t){return t.values}),u=a.filter(function(t){return 0<t.length}).join(n.separator),s=(e=[]).concat.apply(e,t(l));return n.nested||n.numberedParameters&&!function(){var t=void 0!==n.numberedParametersStartAt?n.numberedParametersStartAt:1,e=n.parameterCharacter.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&");u=u.replace(new RegExp(e,"g"),function(){return""+n.numberedParametersPrefix+t++})}(),{text:this._applyNestingFormatting(u,!!n.nested),values:s}}},{key:"clone",value:function(){var t=this.blocks.map(function(t){return t.clone()});return new this.constructor(this.options,t)}},{key:"getBlock",value:function(t){var e=this.blocks.filter(function(e){return e instanceof t});return e[0]}}]),a}(p.BaseBuilder),p.Select=function(t){function i(t){var r=arguments.length<=1||void 0===arguments[1]?null:arguments[1];return n(this,i),r=r||[new p.StringBlock(t,"SELECT"),new p.FunctionBlock(t),new p.DistinctBlock(t),new p.GetFieldBlock(t),new p.FromTableBlock(t),new p.JoinBlock(t),new p.WhereBlock(t),new p.GroupByBlock(t),new p.HavingBlock(t),new p.OrderByBlock(t),new p.LimitBlock(t),new p.OffsetBlock(t),new p.UnionBlock(t)],e(this,Object.getPrototypeOf(i).call(this,t,r))}return r(i,t),i}(p.QueryBuilder),p.Update=function(t){function i(t){var r=arguments.length<=1||void 0===arguments[1]?null:arguments[1];return n(this,i),r=r||[new p.StringBlock(t,"UPDATE"),new p.UpdateTableBlock(t),new p.SetFieldBlock(t),new p.WhereBlock(t),new p.OrderByBlock(t),new p.LimitBlock(t)],e(this,Object.getPrototypeOf(i).call(this,t,r));
}return r(i,t),i}(p.QueryBuilder),p.Delete=function(t){function i(t){var r=arguments.length<=1||void 0===arguments[1]?null:arguments[1];return n(this,i),r=r||[new p.StringBlock(t,"DELETE"),new p.FromTableBlock(o({},t,{singleTable:!0})),new p.JoinBlock(t),new p.WhereBlock(t),new p.OrderByBlock(t),new p.LimitBlock(t)],e(this,Object.getPrototypeOf(i).call(this,t,r))}return r(i,t),i}(p.QueryBuilder),p.Insert=function(t){function i(t){var r=arguments.length<=1||void 0===arguments[1]?null:arguments[1];return n(this,i),r=r||[new p.StringBlock(t,"INSERT"),new p.IntoTableBlock(t),new p.InsertFieldValueBlock(t),new p.InsertFieldsFromQueryBlock(t)],e(this,Object.getPrototypeOf(i).call(this,t,r))}return r(i,t),i}(p.QueryBuilder);var g={VERSION:"5.0.4",flavour:h,expr:function(t){return new p.Expression(t)},"case":function(t,e){return new p.Case(t,e)},select:function(t,e){return new p.Select(t,e)},update:function(t,e){return new p.Update(t,e)},insert:function(t,e){return new p.Insert(t,e)},"delete":function(t,e){return new p.Delete(t,e)},str:function(){var t=new p.FunctionBlock;return t["function"].apply(t,arguments),t},registerValueHandler:p.registerValueHandler};return g.remove=g["delete"],g.cls=p,g}var v=function g(t,e,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:g(i,e,r)}if("value"in n)return n.value;var o=n.get;if(void 0!==o)return o.call(r)},d=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}}(),y="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol?"symbol":typeof t},p=h();return p.flavours={},p.useFlavour=function(){var t=arguments.length<=0||void 0===arguments[0]?null:arguments[0];if(!t)return p;if(p.flavours[t]instanceof Function){var e=h(t);return p.flavours[t].call(null,e),e.flavours=p.flavours,e.useFlavour=p.useFlavour,e}throw new Error("Flavour not available: "+t)},p.flavours.mssql=function(t){var a=t.cls;a.DefaultQueryBuilderOptions.replaceSingleQuotes=!0,a.DefaultQueryBuilderOptions.autoQuoteAliasNames=!1,a.DefaultQueryBuilderOptions.numberedParametersPrefix="@",t.registerValueHandler(Date,function(t){return"'"+t.getUTCFullYear()+"-"+(t.getUTCMonth()+1)+"-"+t.getUTCDate()+" "+t.getUTCHours()+":"+t.getUTCMinutes()+":"+t.getUTCSeconds()+"'"}),a.MssqlLimitOffsetTopBlock=function(t){function i(t){n(this,i);var o=e(this,Object.getPrototypeOf(i).call(this,t));o._limits=null,o._offsets=null;var l=function(t){t=this._sanitizeLimitOffset(t),this._parent._limits=t};return o.ParentBlock=function(t){function i(t){n(this,i);var r=e(this,Object.getPrototypeOf(i).call(this,t.options));return r._parent=t,r}return r(i,t),i}(a.Block),o.LimitBlock=function(t){function i(t){n(this,i);var r=e(this,Object.getPrototypeOf(i).call(this,t));return r.limit=l,r}return r(i,t),d(i,[{key:"_toParamString",value:function(){var t="";return this._parent._limits&&this._parent._offsets&&(t="FETCH NEXT "+this._parent._limits+" ROWS ONLY"),{text:t,values:[]}}}]),i}(o.ParentBlock),o.TopBlock=function(t){function i(t){n(this,i);var r=e(this,Object.getPrototypeOf(i).call(this,t));return r.top=l,r}return r(i,t),d(i,[{key:"_toParamString",value:function(){var t="";return this._parent._limits&&!this._parent._offsets&&(t="TOP ("+this._parent._limits+")"),{text:t,values:[]}}}]),i}(o.ParentBlock),o.OffsetBlock=function(t){function i(){return n(this,i),e(this,Object.getPrototypeOf(i).apply(this,arguments))}return r(i,t),d(i,[{key:"offset",value:function(t){this._parent._offsets=this._sanitizeLimitOffset(t)}},{key:"_toParamString",value:function(){var t="";return this._parent._offsets&&(t="OFFSET "+this._parent._offsets+" ROWS"),{text:t,values:[]}}}]),i}(o.ParentBlock),o}return r(i,t),d(i,[{key:"LIMIT",value:function(){return new this.LimitBlock(this)}},{key:"TOP",value:function(){return new this.TopBlock(this)}},{key:"OFFSET",value:function(){return new this.OffsetBlock(this)}}]),i}(a.Block),a.MssqlUpdateTopBlock=function(t){function i(t){n(this,i);var r=e(this,Object.getPrototypeOf(i).call(this,t));return r._limits=null,r.limit=r.top=function(t){r._limits=r._sanitizeLimitOffset(t)},r}return r(i,t),d(i,[{key:"_toParamString",value:function(){return{text:this._limits?"TOP ("+this._limits+")":"",values:[]}}}]),i}(a.Block),a.MssqlInsertFieldValueBlock=function(t){function i(t){n(this,i);var r=e(this,Object.getPrototypeOf(i).call(this,t));return r._outputs=[],r}return r(i,t),d(i,[{key:"output",value:function(t){var e=this;"string"==typeof t?this._outputs.push("INSERTED."+this._sanitizeField(t)):t.forEach(function(t){e._outputs.push("INSERTED."+e._sanitizeField(t))})}},{key:"_toParamString",value:function(t){var e=v(Object.getPrototypeOf(i.prototype),"_toParamString",this).call(this,t);if(e.text.length&&0<this._outputs.length){var 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}(a.InsertFieldValueBlock),a.MssqlUpdateDeleteOutputBlock=function(t){function o(t){n(this,o);var r=e(this,Object.getPrototypeOf(o).call(this,t));return r._outputs=[],r}return r(o,t),d(o,[{key:"outputs",value:function(t){for(var e in t)this.output(e,t[e])}},{key:"output",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?null:arguments[1];t=this._sanitizeField(t),e=e?this._sanitizeFieldAlias(e):e,this._outputs.push({name:this.options.forDelete?"DELETED."+t:"INSERTED."+t,alias:e})}},{key:"_toParamString",value:function(t){var e="";if(this._outputs.length){var r=!0,n=!1,o=void 0;try{for(var a,l=this._outputs[Symbol.iterator]();!(r=(a=l.next()).done);r=!0){var u=a.value;e=i(e,", "),e+=u.name,u.alias&&(e+=" AS "+this._formatFieldAlias(u.alias))}}catch(s){n=!0,o=s}finally{try{!r&&l["return"]&&l["return"]()}finally{if(n)throw o}}e="OUTPUT "+e}return{text:e,values:[]}}}]),o}(a.Block),a.Select=function(t){function i(t){var r=arguments.length<=1||void 0===arguments[1]?null:arguments[1];n(this,i);var o=new a.MssqlLimitOffsetTopBlock(t);return r=r||[new a.StringBlock(t,"SELECT"),new a.DistinctBlock(t),o.TOP(),new a.GetFieldBlock(t),new a.FromTableBlock(t),new a.JoinBlock(t),new a.WhereBlock(t),new a.GroupByBlock(t),new a.OrderByBlock(t),o.OFFSET(),o.LIMIT(),new a.UnionBlock(t)],e(this,Object.getPrototypeOf(i).call(this,t,r))}return r(i,t),i}(a.QueryBuilder),a.Update=function(t){function i(t){var r=arguments.length<=1||void 0===arguments[1]?null:arguments[1];return n(this,i),r=r||[new a.StringBlock(t,"UPDATE"),new a.MssqlUpdateTopBlock(t),new a.UpdateTableBlock(t),new a.SetFieldBlock(t),new a.MssqlUpdateDeleteOutputBlock(t),new a.WhereBlock(t)],e(this,Object.getPrototypeOf(i).call(this,t,r))}return r(i,t),i}(a.QueryBuilder),a.Delete=function(t){function i(t){var r=arguments.length<=1||void 0===arguments[1]?null:arguments[1];return n(this,i),r=r||[new a.StringBlock(t,"DELETE"),new a.FromTableBlock(o({},t,{singleTable:!0})),new a.JoinBlock(t),new a.MssqlUpdateDeleteOutputBlock(o({},t,{forDelete:!0})),new a.WhereBlock(t),new a.OrderByBlock(t),new a.LimitBlock(t)],e(this,Object.getPrototypeOf(i).call(this,t,r))}return r(i,t),i}(a.QueryBuilder),a.Insert=function(t){function i(t){var r=arguments.length<=1||void 0===arguments[1]?null:arguments[1];return n(this,i),r=r||[new a.StringBlock(t,"INSERT"),new a.IntoTableBlock(t),new a.MssqlInsertFieldValueBlock(t),new a.InsertFieldsFromQueryBlock(t)],e(this,Object.getPrototypeOf(i).call(this,t,r))}return r(i,t),i}(a.QueryBuilder)},p.flavours.mysql=function(a){var l=a.cls;l.TargetTableBlock=function(t){function i(){return n(this,i),e(this,Object.getPrototypeOf(i).apply(this,arguments))}return r(i,t),d(i,[{key:"target",value:function(t){this["function"](this._sanitizeTable(t))}}]),i}(l.FunctionBlock),l.MysqlOnDuplicateKeyUpdateBlock=function(o){function a(){return n(this,a),e(this,Object.getPrototypeOf(a).apply(this,arguments))}return r(a,o),d(a,[{key:"onDupUpdate",value:function(t,e,r){this._set(t,e,r)}},{key:"_toParamString",value:function(){for(var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],r="",n=[],o=0;o<this._fields.length;++o){r=i(r,", ");var a=this._fields[o],l=this._values[0][o],u=this._valueOptions[0][o];if("undefined"==typeof l)r+=a;else{var s=this._buildString(a+" = "+this.options.parameterCharacter,[l],{buildParameterized:e.buildParameterized,formattingOptions:u});r+=s.text,n.push.apply(n,t(s.values))}}return{text:r.length?"ON DUPLICATE KEY UPDATE "+r:"",values:n}}}]),a}(l.AbstractSetFieldBlock),l.Insert=function(t){function i(t){var r=arguments.length<=1||void 0===arguments[1]?null:arguments[1];return n(this,i),r=r||[new l.StringBlock(t,"INSERT"),new l.IntoTableBlock(t),new l.InsertFieldValueBlock(t),new l.InsertFieldsFromQueryBlock(t),new l.MysqlOnDuplicateKeyUpdateBlock(t)],e(this,Object.getPrototypeOf(i).call(this,t,r))}return r(i,t),i}(l.QueryBuilder),l.Delete=function(t){function i(t){var r=arguments.length<=1||void 0===arguments[1]?null:arguments[1];return n(this,i),r=r||[new l.StringBlock(t,"DELETE"),new l.TargetTableBlock(t),new l.FromTableBlock(o({},t,{singleTable:!0})),new l.JoinBlock(t),new l.WhereBlock(t),new l.OrderByBlock(t),new l.LimitBlock(t)],e(this,Object.getPrototypeOf(i).call(this,t,r))}return r(i,t),i}(l.QueryBuilder)},p.flavours.postgres=function(t){var i=t.cls;i.DefaultQueryBuilderOptions.numberedParameters=!0,i.DefaultQueryBuilderOptions.numberedParametersStartAt=1,i.DefaultQueryBuilderOptions.autoQuoteAliasNames=!1,i.DefaultQueryBuilderOptions.useAsForTableAliasNames=!0,i.ReturningBlock=function(t){function i(t){n(this,i);var r=e(this,Object.getPrototypeOf(i).call(this,t));return r._str=null,r}return r(i,t),d(i,[{key:"returning",value:function(t){this._str=this._sanitizeField(t)}},{key:"_toParamString",value:function(){return{text:this._str?"RETURNING "+this._str:"",values:[]}}}]),i}(i.Block),i.Insert=function(t){function o(t){var r=arguments.length<=1||void 0===arguments[1]?null:arguments[1];return n(this,o),r=r||[new i.StringBlock(t,"INSERT"),new i.IntoTableBlock(t),new i.InsertFieldValueBlock(t),new i.InsertFieldsFromQueryBlock(t),new i.ReturningBlock(t)],e(this,Object.getPrototypeOf(o).call(this,t,r))}return r(o,t),o}(i.QueryBuilder),i.Update=function(t){function o(t){var r=arguments.length<=1||void 0===arguments[1]?null:arguments[1];return n(this,o),r=r||[new i.StringBlock(t,"UPDATE"),new i.UpdateTableBlock(t),new i.SetFieldBlock(t),new i.FromTableBlock(t),new i.WhereBlock(t),new i.OrderByBlock(t),new i.LimitBlock(t),new i.ReturningBlock(t)],e(this,Object.getPrototypeOf(o).call(this,t,r))}return r(o,t),o}(i.QueryBuilder),i.Delete=function(t){function a(t){var r=arguments.length<=1||void 0===arguments[1]?null:arguments[1];return n(this,a),r=r||[new i.StringBlock(t,"DELETE"),new i.FromTableBlock(o({},t,{singleTable:!0})),new i.JoinBlock(t),new i.WhereBlock(t),new i.OrderByBlock(t),new i.LimitBlock(t),new i.ReturningBlock(t)],e(this,Object.getPrototypeOf(a).call(this,t,r))}return r(a,t),a}(i.QueryBuilder)},p});