2013-09-13 16:58:38 -04:00
|
|
|
// JoinClause
|
|
|
|
// ---------
|
2013-09-03 22:25:54 -04:00
|
|
|
(function(define) {
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
define(function(require, exports) {
|
|
|
|
|
2013-09-17 07:15:18 -04:00
|
|
|
// The "JoinClause" is an object holding any necessary info about a join,
|
|
|
|
// including the type, and any associated tables & columns being joined.
|
2013-09-03 22:25:54 -04:00
|
|
|
var JoinClause = function(type, table) {
|
2013-09-13 10:51:12 -04:00
|
|
|
this.joinType = type;
|
|
|
|
this.table = table;
|
|
|
|
this.clauses = [];
|
2013-09-03 22:25:54 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
JoinClause.prototype = {
|
|
|
|
|
2013-09-17 07:15:18 -04:00
|
|
|
// Adds an "on" clause to the current join object.
|
2013-09-03 22:25:54 -04:00
|
|
|
on: function(first, operator, second) {
|
|
|
|
this.clauses.push({first: first, operator: operator, second: second, bool: 'and'});
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2013-09-17 07:15:18 -04:00
|
|
|
// Adds an "and on" clause to the current join object.
|
2013-09-03 22:25:54 -04:00
|
|
|
andOn: function() {
|
|
|
|
return this.on.apply(this, arguments);
|
|
|
|
},
|
|
|
|
|
2013-09-17 07:15:18 -04:00
|
|
|
// Adds an "or on" clause to the current join object.
|
2013-09-03 22:25:54 -04:00
|
|
|
orOn: function(first, operator, second) {
|
|
|
|
this.clauses.push({first: first, operator: operator, second: second, bool: 'or'});
|
|
|
|
return this;
|
2013-09-13 10:51:12 -04:00
|
|
|
},
|
|
|
|
|
2013-09-17 07:15:18 -04:00
|
|
|
// Explicitly set the type of join, useful within a function when creating a grouped join.
|
2013-09-13 10:51:12 -04:00
|
|
|
type: function(type) {
|
|
|
|
this.joinType = type;
|
|
|
|
return this;
|
2013-09-03 22:25:54 -04:00
|
|
|
}
|
2013-09-13 10:51:12 -04:00
|
|
|
|
2013-09-03 22:25:54 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
exports.JoinClause = JoinClause;
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
})(
|
|
|
|
typeof define === 'function' && define.amd ? define : function (factory) { factory(require, exports); }
|
|
|
|
);
|