From e6ed027f44869565d8f8a780ff5f9853224cba22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martial=20S=C3=A9ron?= Date: Wed, 17 Jan 2018 17:28:17 +0100 Subject: [PATCH 1/2] Add GetFieldBlock methods to remove fields from final result set --- src/core.js | 31 +++++++++++++++++++++++++++++++ test/blocks.test.coffee | 29 +++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/src/core.js b/src/core.js index 327979a4..86d25721 100644 --- a/src/core.js +++ b/src/core.js @@ -1209,6 +1209,37 @@ function _buildSquel(flavour = null) { }); } + /** + # Remove the given field from the final result set. + # + */ + removeField (field) { + field = this._sanitizeField(field); + + // search by alias + let index = this._fields.findIndex((f) => { + return f.alias === field; + }); + + if (index === -1) { + // search by name + index = this._fields.findIndex((f) => { + return f.name === field; + }); + } + + if (index !== -1) { + this._fields.splice(index, 1); + } + } + + /** + # Remove all fields from the final result set. + # + */ + removeAllFields () { + this._fields = []; + } _toParamString (options = {}) { let { queryBuilder, buildParameterized } = options; diff --git a/test/blocks.test.coffee b/test/blocks.test.coffee index 6c11706f..055c7730 100644 --- a/test/blocks.test.coffee +++ b/test/blocks.test.coffee @@ -499,6 +499,35 @@ test['Blocks'] = assert.same expected, @inst._fields + 'remove inputs': -> + @inst.field('field1') + @inst.field('field2', 'alias2') + @inst.field('field1', 'alias1') + + @inst.removeField('alias1') + @inst.removeField('field2') + + expected = [ + { + name: 'field1', + alias: null + options: {}, + } + ] + + assert.same expected, @inst._fields + + 'remove all inputs': -> + @inst.field('field1') + @inst.field('field2', 'alias2') + @inst.field('field1', 'alias1') + + @inst.removeAllFields() + + expected = [] + + assert.same expected, @inst._fields + 'field() - discard duplicates': 'saves inputs': -> @inst.field('field1') From a52e7330007725d3493d27e70bf1589b45a51bc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martial=20S=C3=A9ron?= Date: Wed, 17 Jan 2018 17:44:19 +0100 Subject: [PATCH 2/2] Commit builds --- dist/squel-basic.js | 38 ++++++++++++++++++++++++++++++++++++++ dist/squel-basic.min.js | 4 ++-- dist/squel.js | 38 ++++++++++++++++++++++++++++++++++++++ dist/squel.min.js | 4 ++-- 4 files changed, 80 insertions(+), 4 deletions(-) diff --git a/dist/squel-basic.js b/dist/squel-basic.js index b2640123..ac9b2f28 100644 --- a/dist/squel-basic.js +++ b/dist/squel-basic.js @@ -1571,6 +1571,44 @@ function _buildSquel() { options: options }); } + + /** + # Remove the given field from the final result set. + # + */ + + }, { + key: 'removeField', + value: function removeField(field) { + field = this._sanitizeField(field); + + // search by alias + var index = this._fields.findIndex(function (f) { + return f.alias === field; + }); + + if (index === -1) { + // search by name + index = this._fields.findIndex(function (f) { + return f.name === field; + }); + } + + if (index !== -1) { + this._fields.splice(index, 1); + } + } + + /** + # Remove all fields from the final result set. + # + */ + + }, { + key: 'removeAllFields', + value: function removeAllFields() { + this._fields = []; + } }, { key: '_toParamString', value: function _toParamString() { diff --git a/dist/squel-basic.min.js b/dist/squel-basic.min.js index 58db9d73..3cb9d9f4 100644 --- a/dist/squel-basic.min.js +++ b/dist/squel-basic.min.js @@ -1,2 +1,2 @@ -/*! squel | https://github.com/hiddentao/squel | BSD license */!function(t,e){"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?module.exports=e():t.squel=e()}(this,function(){"use strict";function t(t,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;n0&&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;n1?e-1:0),n=1;n0&&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;n0&&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;n0&&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 00&&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(00&&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;oa.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;l0&&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;n0&&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;n1?e-1:0),n=1;n2?r-2:0),i=2;i0&&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;o0&&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 01&&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;r0&&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)},_}); \ No newline at end of file +/*! 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;n0&&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;n1?e-1:0),n=1;n0&&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;n0&&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;n0&&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 00&&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:"removeField",value:function(t){t=this._sanitizeField(t);var e=this._fields.findIndex(function(e){return e.alias===t});e===-1&&(e=this._fields.findIndex(function(e){return e.name===t})),e!==-1&&this._fields.splice(e,1)}},{key:"removeAllFields",value:function(){this._fields=[]}},{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(00&&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;oa.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;l0&&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;n0&&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;n1?e-1:0),n=1;n2?r-2:0),i=2;i0&&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;o0&&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 01&&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;r0&&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)},_}); \ No newline at end of file diff --git a/dist/squel.js b/dist/squel.js index ae64abba..cd47447b 100644 --- a/dist/squel.js +++ b/dist/squel.js @@ -1571,6 +1571,44 @@ function _buildSquel() { options: options }); } + + /** + # Remove the given field from the final result set. + # + */ + + }, { + key: 'removeField', + value: function removeField(field) { + field = this._sanitizeField(field); + + // search by alias + var index = this._fields.findIndex(function (f) { + return f.alias === field; + }); + + if (index === -1) { + // search by name + index = this._fields.findIndex(function (f) { + return f.name === field; + }); + } + + if (index !== -1) { + this._fields.splice(index, 1); + } + } + + /** + # Remove all fields from the final result set. + # + */ + + }, { + key: 'removeAllFields', + value: function removeAllFields() { + this._fields = []; + } }, { key: '_toParamString', value: function _toParamString() { diff --git a/dist/squel.min.js b/dist/squel.min.js index b1f7586c..a971999a 100644 --- a/dist/squel.min.js +++ b/dist/squel.min.js @@ -1,2 +1,2 @@ -/*! squel | https://github.com/hiddentao/squel | BSD license */!function(t,e){"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?module.exports=e():t.squel=e()}(this,function(){"use strict";function t(t,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;n0&&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;n1?e-1:0),n=1;n0&&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;n0&&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;n0&&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 00&&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(00&&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;ol.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;a0&&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;n0&&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;n1?e-1:0),n=1;n2?r-2:0),i=2;i0&&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;o0&&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 01&&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;r0&&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&&01&&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;i1&&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;i1&&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;n1&&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)},_}); \ No newline at end of file +/*! 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;n0&&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;n1?e-1:0),n=1;n0&&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;n0&&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;n0&&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 00&&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:"removeField",value:function(t){t=this._sanitizeField(t);var e=this._fields.findIndex(function(e){return e.alias===t});e===-1&&(e=this._fields.findIndex(function(e){return e.name===t})),e!==-1&&this._fields.splice(e,1)}},{key:"removeAllFields",value:function(){this._fields=[]}},{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(00&&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;ol.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;a0&&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;n0&&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;n1?e-1:0),n=1;n2?r-2:0),i=2;i0&&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;o0&&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 01&&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;r0&&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&&01&&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;i1&&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;i1&&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;n1&&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)},_}); \ No newline at end of file