Comparing version 0.11.0 to 0.12.0
@@ -94,2 +94,8 @@ 'use strict'; | ||
Column.prototype.distinct = function() { | ||
var context = contextify(this); | ||
context.distinct = true; | ||
return new ColumnNode(context); | ||
}; | ||
binaryMethod('equals', '='); | ||
@@ -96,0 +102,0 @@ binaryMethod('equal', '='); |
@@ -290,7 +290,13 @@ 'use strict'; | ||
var txt = ""; | ||
var closeParen = false; | ||
if(inSelectClause) { | ||
if (columnNode.asArray) { | ||
closeParen = true; | ||
txt += this._arrayAggFunctionName+'('; | ||
} else if (columnNode.aggCount) { | ||
closeParen = true; | ||
txt += 'COUNT('; | ||
} else if (columnNode.distinct === true) { | ||
closeParen = true; | ||
txt += 'DISTINCT(' | ||
} | ||
@@ -315,3 +321,3 @@ } | ||
} | ||
if(inSelectClause && (columnNode.asArray || columnNode.aggCount)) { | ||
if(closeParen) { | ||
txt += ')'; | ||
@@ -318,0 +324,0 @@ } |
@@ -17,2 +17,3 @@ 'use strict'; | ||
this.dataType = config.dataType; | ||
this.distinct = config.distinct; | ||
}, | ||
@@ -19,0 +20,0 @@ as: function(alias) { |
@@ -74,2 +74,10 @@ 'use strict'; | ||
where: function(node) { | ||
if(arguments.length > 1) { | ||
//allow multiple where clause arguments | ||
var args = sliced(arguments); | ||
for(var i = 0; i < args.length; i++) { | ||
this.where(args[i]); | ||
} | ||
return this; | ||
} | ||
//calling #where twice functions like calling #where & then #and | ||
@@ -76,0 +84,0 @@ if(this.whereClause) return this.and(node); |
@@ -38,2 +38,6 @@ 'use strict'; | ||
var right = normalizeNode(this.table, other); | ||
//calling 'or' without an initial 'where' | ||
if(!this.nodes.length) { | ||
return this.add(other); | ||
} | ||
return this.nodes.push(new BinaryNode({ | ||
@@ -40,0 +44,0 @@ left: this.nodes.pop(), |
@@ -152,2 +152,14 @@ 'use strict'; | ||
Table.prototype.and = function() { | ||
var query = new Query(this); | ||
query.where.apply(query, arguments); | ||
return query; | ||
}; | ||
Table.prototype.or = function() { | ||
var query = new Query(this); | ||
query.or.apply(query, arguments); | ||
return query; | ||
}; | ||
module.exports = Table; |
@@ -5,3 +5,3 @@ { | ||
"description": "sql builder", | ||
"version": "0.11.0", | ||
"version": "0.12.0", | ||
"homepage": "https://github.com/brianc/node-sql", | ||
@@ -8,0 +8,0 @@ "repository": { |
89851
68
2395