Comparing version 1.0.5 to 1.0.6
# Changelog for [squel](https://github.com/hiddentao/squel) | ||
## 4 Jan 2013 (1.0.6) | ||
* Squel can now be told to auto-quote table and field names. | ||
## 3 Nov 2012 (1.0.5) | ||
@@ -5,0 +9,0 @@ |
{ | ||
"name": "squel", | ||
"description": "SQL query string builder", | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"author": "Ramesh Nair <ram@hiddentao.com> (http://www.hiddentao.com/)", | ||
@@ -17,3 +17,4 @@ "contributors": [ | ||
"chai": "1.3.0", | ||
"sinon": "1.5.0" | ||
"sinon": "1.5.0", | ||
"underscore": "1.4.3" | ||
}, | ||
@@ -20,0 +21,0 @@ "keywords": ["sql", "database", "rdbms"], |
@@ -12,3 +12,3 @@ # squel - SQL query string builder for Javascript | ||
* Uses method chaining for ease of use. | ||
* Well tested (over 300 [vows](http://vowsjs.org/)). | ||
* Well tested (~200 tests). | ||
* Small: ~3 KB when minified and gzipped. | ||
@@ -15,0 +15,0 @@ |
62
squel.js
@@ -30,3 +30,3 @@ // Generated by CoffeeScript 1.3.3 | ||
(function() { | ||
var Cloneable, DefaultInsertBuilderOptions, DefaultUpdateBuilderOptions, Delete, Expression, Insert, JoinWhereOrderLimit, QueryBuilder, Select, Update, WhereOrderLimit, _export, _extend, | ||
var Cloneable, DefaultQueryBuilderOptions, Delete, Expression, Insert, JoinWhereOrderLimit, QueryBuilder, Select, Update, WhereOrderLimit, _export, _extend, | ||
__slice = [].slice, | ||
@@ -181,3 +181,6 @@ __hasProp = {}.hasOwnProperty, | ||
DefaultInsertBuilderOptions = DefaultUpdateBuilderOptions = { | ||
DefaultQueryBuilderOptions = { | ||
autoQuoteTableNames: false, | ||
autoQuoteFieldNames: false, | ||
nameQuoteCharacter: '`', | ||
usingValuePlaceholders: false | ||
@@ -190,4 +193,4 @@ }; | ||
function QueryBuilder() { | ||
return QueryBuilder.__super__.constructor.apply(this, arguments); | ||
function QueryBuilder(options) { | ||
this.options = _extend({}, DefaultQueryBuilderOptions, options); | ||
} | ||
@@ -227,7 +230,19 @@ | ||
QueryBuilder.prototype._sanitizeField = function(item) { | ||
return this._sanitizeName(item, "field name"); | ||
var sanitized; | ||
sanitized = this._sanitizeName(item, "field name"); | ||
if (this.options.autoQuoteFieldNames) { | ||
return "" + this.options.nameQuoteCharacter + sanitized + this.options.nameQuoteCharacter; | ||
} else { | ||
return sanitized; | ||
} | ||
}; | ||
QueryBuilder.prototype._sanitizeTable = function(item) { | ||
return this._sanitizeName(item, "table name"); | ||
var sanitized; | ||
sanitized = this._sanitizeName(item, "table name"); | ||
if (this.options.autoQuoteTableNames) { | ||
return "" + this.options.nameQuoteCharacter + sanitized + this.options.nameQuoteCharacter; | ||
} else { | ||
return sanitized; | ||
} | ||
}; | ||
@@ -256,3 +271,3 @@ | ||
QueryBuilder.prototype._formatValue = function(value, options) { | ||
QueryBuilder.prototype._formatValue = function(value) { | ||
if (null === value) { | ||
@@ -263,3 +278,3 @@ value = "NULL"; | ||
} else if ("number" !== typeof value) { | ||
if (!options || false === options.usingValuePlaceholders) { | ||
if (false === this.options.usingValuePlaceholders) { | ||
value = "'" + value + "'"; | ||
@@ -279,3 +294,3 @@ } | ||
function WhereOrderLimit() { | ||
function WhereOrderLimit(options) { | ||
this._limitString = __bind(this._limitString, this); | ||
@@ -292,3 +307,3 @@ | ||
this.where = __bind(this.where, this); | ||
WhereOrderLimit.__super__.constructor.apply(this, arguments); | ||
WhereOrderLimit.__super__.constructor.call(this, options); | ||
this.wheres = []; | ||
@@ -367,3 +382,3 @@ this.orders = []; | ||
function JoinWhereOrderLimit() { | ||
function JoinWhereOrderLimit(options) { | ||
this._joinString = __bind(this._joinString, this); | ||
@@ -378,3 +393,3 @@ | ||
this.join = __bind(this.join, this); | ||
JoinWhereOrderLimit.__super__.constructor.apply(this, arguments); | ||
JoinWhereOrderLimit.__super__.constructor.call(this, options); | ||
this.joins = []; | ||
@@ -458,3 +473,3 @@ } | ||
function Select() { | ||
function Select(options) { | ||
this.toString = __bind(this.toString, this); | ||
@@ -471,3 +486,3 @@ | ||
this.distinct = __bind(this.distinct, this); | ||
Select.__super__.constructor.apply(this, arguments); | ||
Select.__super__.constructor.call(this, options); | ||
this.froms = []; | ||
@@ -598,6 +613,5 @@ this.fields = []; | ||
this.table = __bind(this.table, this); | ||
Update.__super__.constructor.apply(this, arguments); | ||
Update.__super__.constructor.call(this, options); | ||
this.tables = []; | ||
this.fields = {}; | ||
this.options = _extend({}, DefaultUpdateBuilderOptions, options); | ||
} | ||
@@ -665,3 +679,3 @@ | ||
} | ||
fields += "" + field + " = " + (this._formatValue(this.fields[field], this.options)); | ||
fields += "" + field + " = " + (this._formatValue(this.fields[field])); | ||
} | ||
@@ -734,6 +748,5 @@ ret += " SET " + fields; | ||
this.into = __bind(this.into, this); | ||
Insert.__super__.constructor.apply(this, arguments); | ||
Insert.__super__.constructor.call(this, options); | ||
this.table = null; | ||
this.fields = {}; | ||
this.options = _extend({}, DefaultInsertBuilderOptions, options); | ||
} | ||
@@ -783,3 +796,3 @@ | ||
} | ||
values += this._formatValue(this.fields[field], this.options); | ||
values += this._formatValue(this.fields[field]); | ||
} | ||
@@ -797,4 +810,4 @@ return "INSERT INTO " + this.table + " (" + fields + ") VALUES (" + values + ")"; | ||
}, | ||
select: function() { | ||
return new Select; | ||
select: function(options) { | ||
return new Select(options); | ||
}, | ||
@@ -807,5 +820,6 @@ update: function(options) { | ||
}, | ||
"delete": function() { | ||
return new Delete; | ||
"delete": function(options) { | ||
return new Delete(options); | ||
}, | ||
DefaultQueryBuilderOptions: DefaultQueryBuilderOptions, | ||
Cloneable: Cloneable, | ||
@@ -812,0 +826,0 @@ Expression: Expression, |
@@ -25,2 +25,2 @@ // Generated by CoffeeScript 1.3.3 | ||
OTHER DEALINGS IN THE SOFTWARE. | ||
*/(function(){var e,t,n,r,i,s,o,u,a,f,l,c,h,p=[].slice,d={}.hasOwnProperty,v=function(e,t){return function(){return e.apply(t,arguments)}},m=function(e,t){function r(){this.constructor=e}for(var n in t)d.call(t,n)&&(e[n]=t[n]);return r.prototype=t.prototype,e.prototype=new r,e.__super__=t.prototype,e};h=function(){var e,t,n,r,i,s,o;e=arguments[0],n=2<=arguments.length?p.call(arguments,1):[];if(n)for(s=0,o=n.length;s<o;s++){r=n[s];if(r)for(t in r){if(!d.call(r,t))continue;i=r[t],e[t]=i}}return e},e=function(){function e(){}return e.prototype.clone=function(){var e;return e=new this.constructor,h(e,JSON.parse(JSON.stringify(this)))},e}(),i=function(){function t(){this.toString=v(this.toString,this),this.or=v(this.or,this),this.and=v(this.and,this),this.end=v(this.end,this),this.or_begin=v(this.or_begin,this),this.and_begin=v(this.and_begin,this);var e=this;this.tree={parent:null,nodes:[]},this.current=this.tree,this._begin=function(t){var n;return n={type:t,parent:e.current,nodes:[]},e.current.nodes.push(n),e.current=e.current.nodes[e.current.nodes.length-1],e}}var e;return t.prototype.tree=null,t.prototype.current=null,t.prototype.and_begin=function(){return this._begin("AND")},t.prototype.or_begin=function(){return this._begin("OR")},t.prototype.end=function(){if(!this.current.parent)throw new Error("begin() needs to be called");return this.current=this.current.parent,this},t.prototype.and=function(e){if(!e||"string"!=typeof e)throw new Error("expr must be a string");return this.current.nodes.push({type:"AND",expr:e}),this},t.prototype.or=function(e){if(!e||"string"!=typeof e)throw new Error("expr must be a string");return this.current.nodes.push({type:"OR",expr:e}),this},t.prototype.toString=function(){if(null!==this.current.parent)throw new Error("end() needs to be called");return e(this.tree)},e=function(t){var n,r,i,s,o,u;i="",u=t.nodes;for(s=0,o=u.length;s<o;s++)n=u[s],n.expr!=null?r=n.expr:(r=e(n),""!==r&&(r="("+r+")")),""!==r&&(""!==i&&(i+=" "+n.type+" "),i+=r);return i},t}(),t=n={usingValuePlaceholders:!1},u=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return m(t,e),t.prototype._getObjectClassName=function(e){var t;if(e&&e.constructor&&e.constructor.toString){t=e.constructor.toString().match(/function\s*(\w+)/);if(t&&t.length===2)return t[1]}return void 0},t.prototype._sanitizeCondition=function(e){var t,n;n=typeof e,t=this._getObjectClassName(e);if("Expression"!==t&&"string"!==n)throw new Error("condition must be a string or Expression instance");if("Expression"===n||"Expression"===t)e=e.toString();return e},t.prototype._sanitizeName=function(e,t){if("string"!=typeof e)throw new Error(""+t+" must be a string");return e},t.prototype._sanitizeField=function(e){return this._sanitizeName(e,"field name")},t.prototype._sanitizeTable=function(e){return this._sanitizeName(e,"table name")},t.prototype._sanitizeAlias=function(e){return this._sanitizeName(e,"alias")},t.prototype._sanitizeLimitOffset=function(e){e=parseInt(e);if(0>e||isNaN(e))throw new Error("limit/offset must be >=0");return e},t.prototype._sanitizeValue=function(e){var t;t=typeof e;if(null!==e&&"string"!==t&&"number"!==t&&"boolean"!==t)throw new Error("field value must be a string, number, boolean or null");return e},t.prototype._formatValue=function(e,t){return null===e?e="NULL":"boolean"==typeof e?e=e?"TRUE":"FALSE":"number"!=typeof e&&(!t||!1===t.usingValuePlaceholders)&&(e="'"+e+"'"),e},t}(e),l=function(e){function t(){this._limitString=v(this._limitString,this),this._orderString=v(this._orderString,this),this._whereString=v(this._whereString,this),this.limit=v(this.limit,this),this.order=v(this.order,this),this.where=v(this.where,this),t.__super__.constructor.apply(this,arguments),this.wheres=[],this.orders=[],this.limits=null}return m(t,e),t.prototype.where=function(e){return e=this._sanitizeCondition(e),""!==e&&this.wheres.push(e),this},t.prototype.order=function(e,t){return t==null&&(t=!0),e=this._sanitizeField(e),this.orders.push({field:e,dir:t?"ASC":"DESC"}),this},t.prototype.limit=function(e){return e=this._sanitizeLimitOffset(e),this.limits=e,this},t.prototype._whereString=function(){return 0<this.wheres.length?" WHERE ("+this.wheres.join(") AND (")+")":""},t.prototype._orderString=function(){var e,t,n,r,i;if(0<this.orders.length){t="",i=this.orders;for(n=0,r=i.length;n<r;n++)e=i[n],""!==t&&(t+=", "),t+=""+e.field+" "+e.dir;return" ORDER BY "+t}return""},t.prototype._limitString=function(){return this.limits?" LIMIT "+this.limits:""},t}(u),o=function(e){function t(){this._joinString=v(this._joinString,this),this.outer_join=v(this.outer_join,this),this.right_join=v(this.right_join,this),this.left_join=v(this.left_join,this),this.join=v(this.join,this),t.__super__.constructor.apply(this,arguments),this.joins=[]}return m(t,e),t.prototype.join=function(e,t,n,r){return r==null&&(r="INNER"),e=this._sanitizeTable(e),t&&(t=this._sanitizeAlias(t)),n&&(n=this._sanitizeCondition(n)),this.joins.push({type:r,table:e,alias:t,condition:n}),this},t.prototype.left_join=function(e,t,n){return t==null&&(t=null),n==null&&(n=null),this.join(e,t,n,"LEFT")},t.prototype.right_join=function(e,t,n){return t==null&&(t=null),n==null&&(n=null),this.join(e,t,n,"RIGHT")},t.prototype.outer_join=function(e,t,n){return t==null&&(t=null),n==null&&(n=null),this.join(e,t,n,"OUTER")},t.prototype._joinString=function(){var e,t,n,r,i;t="",i=this.joins||[];for(n=0,r=i.length;n<r;n++)e=i[n],t+=" "+e.type+" JOIN "+e.table,e.alias&&(t+=" `"+e.alias+"`"),e.condition&&(t+=" ON ("+e.condition+")");return t},t}(l),a=function(e){function t(){this.toString=v(this.toString,this),this.offset=v(this.offset,this),this.group=v(this.group,this),this.field=v(this.field,this),this.from=v(this.from,this),this.distinct=v(this.distinct,this),t.__super__.constructor.apply(this,arguments),this.froms=[],this.fields=[],this.groups=[],this.offsets=null,this.useDistinct=!1}return m(t,e),t.prototype.distinct=function(){return this.useDistinct=!0,this},t.prototype.from=function(e,t){return t==null&&(t=null),e=this._sanitizeTable(e),t&&(t=this._sanitizeAlias(t)),this.froms.push({name:e,alias:t}),this},t.prototype.field=function(e,t){return t==null&&(t=null),e=this._sanitizeField(e),t&&(t=this._sanitizeAlias(t)),this.fields.push({name:e,alias:t}),this},t.prototype.group=function(e){return e=this._sanitizeField(e),this.groups.push(e),this},t.prototype.offset=function(e){return e=this._sanitizeLimitOffset(e),this.offsets=e,this},t.prototype.toString=function(){var e,t,n,r,i,s,o,u,a,f,l,c,h,p,d,v;if(0>=this.froms.length)throw new Error("from() needs to be called");i="SELECT ",this.useDistinct&&(i+="DISTINCT "),n="",p=this.fields;for(u=0,l=p.length;u<l;u++)t=p[u],""!==n&&(n+=", "),n+=t.name,t.alias&&(n+=' AS "'+t.alias+'"');i+=""===n?"*":n,o="",d=this.froms;for(a=0,c=d.length;a<c;a++)s=d[a],""!==o&&(o+=", "),o+=s.name,s.alias&&(o+=" `"+s.alias+"`");i+=" FROM "+o,i+=this._joinString(),i+=this._whereString();if(0<this.groups.length){r="",v=this.groups;for(f=0,h=v.length;f<h;f++)e=v[f],""!==r&&(r+=", "),r+=e;i+=" GROUP BY "+r}return i+=this._orderString(),i+=this._limitString(),this.offsets&&(i+=" OFFSET "+this.offsets),i},t}(o),f=function(e){function t(e){this.toString=v(this.toString,this),this.set=v(this.set,this),this.table=v(this.table,this),t.__super__.constructor.apply(this,arguments),this.tables=[],this.fields={},this.options=h({},n,e)}return m(t,e),t.prototype.table=function(e,t){return t==null&&(t=null),e=this._sanitizeTable(e),t&&(t=this._sanitizeAlias(t)),this.tables.push({name:e,alias:t}),this},t.prototype.set=function(e,t){return e=this._sanitizeField(e),t=this._sanitizeValue(t),this.fields[e]=t,this},t.prototype.toString=function(){var e,t,n,r,i,s,o,u,a,f,l;if(0>=this.tables.length)throw new Error("table() needs to be called");t=function(){var t,n;t=this.fields,n=[];for(e in t){if(!d.call(t,e))continue;n.push(e)}return n}.call(this);if(0>=t.length)throw new Error("set() needs to be called");r="UPDATE ",s="",l=this.tables;for(o=0,a=l.length;o<a;o++)i=l[o],""!==s&&(s+=", "),s+=i.name,i.alias&&(s+=" AS `"+i.alias+"`");r+=s,n="";for(u=0,f=t.length;u<f;u++)e=t[u],""!==n&&(n+=", "),n+=""+e+" = "+this._formatValue(this.fields[e],this.options);return r+=" SET "+n,r+=this._whereString(),r+=this._orderString(),r+=this._limitString(),r},t}(l),r=function(e){function t(){return this.toString=v(this.toString,this),this.from=v(this.from,this),t.__super__.constructor.apply(this,arguments)}return m(t,e),t.prototype.table=null,t.prototype.from=function(e,t){return e=this._sanitizeTable(e),t&&(t=this._sanitizeAlias(t)),this.table={name:e,alias:t},this},t.prototype.toString=function(){var e;if(!this.table)throw new Error("from() needs to be called");return e="DELETE FROM "+this.table.name,this.table.alias&&(e+=" `"+this.table.alias+"`"),e+=this._joinString(),e+=this._whereString(),e+=this._orderString(),e+=this._limitString(),e},t}(o),s=function(e){function n(e){this.toString=v(this.toString,this),this.set=v(this.set,this),this.into=v(this.into,this),n.__super__.constructor.apply(this,arguments),this.table=null,this.fields={},this.options=h({},t,e)}return m(n,e),n.prototype.into=function(e){return e=this._sanitizeTable(e),this.table=e,this},n.prototype.set=function(e,t){return e=this._sanitizeField(e),t=this._sanitizeValue(t),this.fields[e]=t,this},n.prototype.toString=function(){var e,t,n,r,i,s,o;if(!this.table)throw new Error("into() needs to be called");t=function(){var e,t;e=this.fields,t=[];for(r in e){if(!d.call(e,r))continue;t.push(r)}return t}.call(this);if(0>=t.length)throw new Error("set() needs to be called");n="",i="";for(s=0,o=t.length;s<o;s++)e=t[s],""!==n&&(n+=", "),n+=e,""!==i&&(i+=", "),i+=this._formatValue(this.fields[e],this.options);return"INSERT INTO "+this.table+" ("+n+") VALUES ("+i+")"},n}(u),c={expr:function(){return new i},select:function(){return new a},update:function(e){return new f(e)},insert:function(e){return new s(e)},"delete":function(){return new r},Cloneable:e,Expression:i,QueryBuilder:u,WhereOrderLimit:l,JoinWhereOrderLimit:o,Select:a,Update:f,Insert:s,Delete:r},typeof module!="undefined"&&module!==null&&(module.exports=c),typeof window!="undefined"&&window!==null&&(window.squel=c)}).call(this); | ||
*/(function(){var e,t,n,r,i,s,o,u,a,f,l,c,h=[].slice,p={}.hasOwnProperty,d=function(e,t){return function(){return e.apply(t,arguments)}},v=function(e,t){function r(){this.constructor=e}for(var n in t)p.call(t,n)&&(e[n]=t[n]);return r.prototype=t.prototype,e.prototype=new r,e.__super__=t.prototype,e};c=function(){var e,t,n,r,i,s,o;e=arguments[0],n=2<=arguments.length?h.call(arguments,1):[];if(n)for(s=0,o=n.length;s<o;s++){r=n[s];if(r)for(t in r){if(!p.call(r,t))continue;i=r[t],e[t]=i}}return e},e=function(){function e(){}return e.prototype.clone=function(){var e;return e=new this.constructor,c(e,JSON.parse(JSON.stringify(this)))},e}(),r=function(){function t(){this.toString=d(this.toString,this),this.or=d(this.or,this),this.and=d(this.and,this),this.end=d(this.end,this),this.or_begin=d(this.or_begin,this),this.and_begin=d(this.and_begin,this);var e=this;this.tree={parent:null,nodes:[]},this.current=this.tree,this._begin=function(t){var n;return n={type:t,parent:e.current,nodes:[]},e.current.nodes.push(n),e.current=e.current.nodes[e.current.nodes.length-1],e}}var e;return t.prototype.tree=null,t.prototype.current=null,t.prototype.and_begin=function(){return this._begin("AND")},t.prototype.or_begin=function(){return this._begin("OR")},t.prototype.end=function(){if(!this.current.parent)throw new Error("begin() needs to be called");return this.current=this.current.parent,this},t.prototype.and=function(e){if(!e||"string"!=typeof e)throw new Error("expr must be a string");return this.current.nodes.push({type:"AND",expr:e}),this},t.prototype.or=function(e){if(!e||"string"!=typeof e)throw new Error("expr must be a string");return this.current.nodes.push({type:"OR",expr:e}),this},t.prototype.toString=function(){if(null!==this.current.parent)throw new Error("end() needs to be called");return e(this.tree)},e=function(t){var n,r,i,s,o,u;i="",u=t.nodes;for(s=0,o=u.length;s<o;s++)n=u[s],n.expr!=null?r=n.expr:(r=e(n),""!==r&&(r="("+r+")")),""!==r&&(""!==i&&(i+=" "+n.type+" "),i+=r);return i},t}(),t={autoQuoteTableNames:!1,autoQuoteFieldNames:!1,nameQuoteCharacter:"`",usingValuePlaceholders:!1},o=function(e){function n(e){this.options=c({},t,e)}return v(n,e),n.prototype._getObjectClassName=function(e){var t;if(e&&e.constructor&&e.constructor.toString){t=e.constructor.toString().match(/function\s*(\w+)/);if(t&&t.length===2)return t[1]}return void 0},n.prototype._sanitizeCondition=function(e){var t,n;n=typeof e,t=this._getObjectClassName(e);if("Expression"!==t&&"string"!==n)throw new Error("condition must be a string or Expression instance");if("Expression"===n||"Expression"===t)e=e.toString();return e},n.prototype._sanitizeName=function(e,t){if("string"!=typeof e)throw new Error(""+t+" must be a string");return e},n.prototype._sanitizeField=function(e){var t;return t=this._sanitizeName(e,"field name"),this.options.autoQuoteFieldNames?""+this.options.nameQuoteCharacter+t+this.options.nameQuoteCharacter:t},n.prototype._sanitizeTable=function(e){var t;return t=this._sanitizeName(e,"table name"),this.options.autoQuoteTableNames?""+this.options.nameQuoteCharacter+t+this.options.nameQuoteCharacter:t},n.prototype._sanitizeAlias=function(e){return this._sanitizeName(e,"alias")},n.prototype._sanitizeLimitOffset=function(e){e=parseInt(e);if(0>e||isNaN(e))throw new Error("limit/offset must be >=0");return e},n.prototype._sanitizeValue=function(e){var t;t=typeof e;if(null!==e&&"string"!==t&&"number"!==t&&"boolean"!==t)throw new Error("field value must be a string, number, boolean or null");return e},n.prototype._formatValue=function(e){return null===e?e="NULL":"boolean"==typeof e?e=e?"TRUE":"FALSE":"number"!=typeof e&&!1===this.options.usingValuePlaceholders&&(e="'"+e+"'"),e},n}(e),f=function(e){function t(e){this._limitString=d(this._limitString,this),this._orderString=d(this._orderString,this),this._whereString=d(this._whereString,this),this.limit=d(this.limit,this),this.order=d(this.order,this),this.where=d(this.where,this),t.__super__.constructor.call(this,e),this.wheres=[],this.orders=[],this.limits=null}return v(t,e),t.prototype.where=function(e){return e=this._sanitizeCondition(e),""!==e&&this.wheres.push(e),this},t.prototype.order=function(e,t){return t==null&&(t=!0),e=this._sanitizeField(e),this.orders.push({field:e,dir:t?"ASC":"DESC"}),this},t.prototype.limit=function(e){return e=this._sanitizeLimitOffset(e),this.limits=e,this},t.prototype._whereString=function(){return 0<this.wheres.length?" WHERE ("+this.wheres.join(") AND (")+")":""},t.prototype._orderString=function(){var e,t,n,r,i;if(0<this.orders.length){t="",i=this.orders;for(n=0,r=i.length;n<r;n++)e=i[n],""!==t&&(t+=", "),t+=""+e.field+" "+e.dir;return" ORDER BY "+t}return""},t.prototype._limitString=function(){return this.limits?" LIMIT "+this.limits:""},t}(o),s=function(e){function t(e){this._joinString=d(this._joinString,this),this.outer_join=d(this.outer_join,this),this.right_join=d(this.right_join,this),this.left_join=d(this.left_join,this),this.join=d(this.join,this),t.__super__.constructor.call(this,e),this.joins=[]}return v(t,e),t.prototype.join=function(e,t,n,r){return r==null&&(r="INNER"),e=this._sanitizeTable(e),t&&(t=this._sanitizeAlias(t)),n&&(n=this._sanitizeCondition(n)),this.joins.push({type:r,table:e,alias:t,condition:n}),this},t.prototype.left_join=function(e,t,n){return t==null&&(t=null),n==null&&(n=null),this.join(e,t,n,"LEFT")},t.prototype.right_join=function(e,t,n){return t==null&&(t=null),n==null&&(n=null),this.join(e,t,n,"RIGHT")},t.prototype.outer_join=function(e,t,n){return t==null&&(t=null),n==null&&(n=null),this.join(e,t,n,"OUTER")},t.prototype._joinString=function(){var e,t,n,r,i;t="",i=this.joins||[];for(n=0,r=i.length;n<r;n++)e=i[n],t+=" "+e.type+" JOIN "+e.table,e.alias&&(t+=" `"+e.alias+"`"),e.condition&&(t+=" ON ("+e.condition+")");return t},t}(f),u=function(e){function t(e){this.toString=d(this.toString,this),this.offset=d(this.offset,this),this.group=d(this.group,this),this.field=d(this.field,this),this.from=d(this.from,this),this.distinct=d(this.distinct,this),t.__super__.constructor.call(this,e),this.froms=[],this.fields=[],this.groups=[],this.offsets=null,this.useDistinct=!1}return v(t,e),t.prototype.distinct=function(){return this.useDistinct=!0,this},t.prototype.from=function(e,t){return t==null&&(t=null),e=this._sanitizeTable(e),t&&(t=this._sanitizeAlias(t)),this.froms.push({name:e,alias:t}),this},t.prototype.field=function(e,t){return t==null&&(t=null),e=this._sanitizeField(e),t&&(t=this._sanitizeAlias(t)),this.fields.push({name:e,alias:t}),this},t.prototype.group=function(e){return e=this._sanitizeField(e),this.groups.push(e),this},t.prototype.offset=function(e){return e=this._sanitizeLimitOffset(e),this.offsets=e,this},t.prototype.toString=function(){var e,t,n,r,i,s,o,u,a,f,l,c,h,p,d,v;if(0>=this.froms.length)throw new Error("from() needs to be called");i="SELECT ",this.useDistinct&&(i+="DISTINCT "),n="",p=this.fields;for(u=0,l=p.length;u<l;u++)t=p[u],""!==n&&(n+=", "),n+=t.name,t.alias&&(n+=' AS "'+t.alias+'"');i+=""===n?"*":n,o="",d=this.froms;for(a=0,c=d.length;a<c;a++)s=d[a],""!==o&&(o+=", "),o+=s.name,s.alias&&(o+=" `"+s.alias+"`");i+=" FROM "+o,i+=this._joinString(),i+=this._whereString();if(0<this.groups.length){r="",v=this.groups;for(f=0,h=v.length;f<h;f++)e=v[f],""!==r&&(r+=", "),r+=e;i+=" GROUP BY "+r}return i+=this._orderString(),i+=this._limitString(),this.offsets&&(i+=" OFFSET "+this.offsets),i},t}(s),a=function(e){function t(e){this.toString=d(this.toString,this),this.set=d(this.set,this),this.table=d(this.table,this),t.__super__.constructor.call(this,e),this.tables=[],this.fields={}}return v(t,e),t.prototype.table=function(e,t){return t==null&&(t=null),e=this._sanitizeTable(e),t&&(t=this._sanitizeAlias(t)),this.tables.push({name:e,alias:t}),this},t.prototype.set=function(e,t){return e=this._sanitizeField(e),t=this._sanitizeValue(t),this.fields[e]=t,this},t.prototype.toString=function(){var e,t,n,r,i,s,o,u,a,f,l;if(0>=this.tables.length)throw new Error("table() needs to be called");t=function(){var t,n;t=this.fields,n=[];for(e in t){if(!p.call(t,e))continue;n.push(e)}return n}.call(this);if(0>=t.length)throw new Error("set() needs to be called");r="UPDATE ",s="",l=this.tables;for(o=0,a=l.length;o<a;o++)i=l[o],""!==s&&(s+=", "),s+=i.name,i.alias&&(s+=" AS `"+i.alias+"`");r+=s,n="";for(u=0,f=t.length;u<f;u++)e=t[u],""!==n&&(n+=", "),n+=""+e+" = "+this._formatValue(this.fields[e]);return r+=" SET "+n,r+=this._whereString(),r+=this._orderString(),r+=this._limitString(),r},t}(f),n=function(e){function t(){return this.toString=d(this.toString,this),this.from=d(this.from,this),t.__super__.constructor.apply(this,arguments)}return v(t,e),t.prototype.table=null,t.prototype.from=function(e,t){return e=this._sanitizeTable(e),t&&(t=this._sanitizeAlias(t)),this.table={name:e,alias:t},this},t.prototype.toString=function(){var e;if(!this.table)throw new Error("from() needs to be called");return e="DELETE FROM "+this.table.name,this.table.alias&&(e+=" `"+this.table.alias+"`"),e+=this._joinString(),e+=this._whereString(),e+=this._orderString(),e+=this._limitString(),e},t}(s),i=function(e){function t(e){this.toString=d(this.toString,this),this.set=d(this.set,this),this.into=d(this.into,this),t.__super__.constructor.call(this,e),this.table=null,this.fields={}}return v(t,e),t.prototype.into=function(e){return e=this._sanitizeTable(e),this.table=e,this},t.prototype.set=function(e,t){return e=this._sanitizeField(e),t=this._sanitizeValue(t),this.fields[e]=t,this},t.prototype.toString=function(){var e,t,n,r,i,s,o;if(!this.table)throw new Error("into() needs to be called");t=function(){var e,t;e=this.fields,t=[];for(r in e){if(!p.call(e,r))continue;t.push(r)}return t}.call(this);if(0>=t.length)throw new Error("set() needs to be called");n="",i="";for(s=0,o=t.length;s<o;s++)e=t[s],""!==n&&(n+=", "),n+=e,""!==i&&(i+=", "),i+=this._formatValue(this.fields[e]);return"INSERT INTO "+this.table+" ("+n+") VALUES ("+i+")"},t}(o),l={expr:function(){return new r},select:function(e){return new u(e)},update:function(e){return new a(e)},insert:function(e){return new i(e)},"delete":function(e){return new n(e)},DefaultQueryBuilderOptions:t,Cloneable:e,Expression:r,QueryBuilder:o,WhereOrderLimit:f,JoinWhereOrderLimit:s,Select:u,Update:a,Insert:i,Delete:n},typeof module!="undefined"&&module!==null&&(module.exports=l),typeof window!="undefined"&&window!==null&&(window.squel=l)}).call(this); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
213066
905
7