Permalink
Browse files

trying to make query.where readable

  • Loading branch information...
1 parent 186f061 commit 85a6bfd9015c5df40b1885285dec76a2f945f7cf Karl Seguin committed May 6, 2012
Showing with 6 additions and 11 deletions.
  1. +6 −11 lib/query.js
View
@@ -32,22 +32,17 @@ var Query = function(sql, params, table) {
self.parseArgs = function(args) {
if(_.isFunction(args[0])) { return self; }
- var columns = " * ";
var where = {};
- //if the first argument is an array, columns are specified
- if(args.length > 0 && _.isArray(args[0])){
- columns = args[0].join(",");
- self.sql = self.sql.replace("*", columns);
- //if the second arg has {columns : "..."} then columns are also specified
- }else if(args.length > 1 && args[1].columns) {
+
+ if(args.length > 0 && _.isArray(args[0])) { //if the first argument is an array, columns are specified
+ self.sql = self.sql.replace("*", args[0].join(","));
+ } else if(args.length > 1 && args[1].columns) { //if the second arg has {columns : "..."} then columns are also specified
self.sql = self.sql.replace("*", args[1].columns);
- //if the argument is numeric (instead of an object) - default it to a PK lookup
- }else if (args.length > 0 && _.isNumber(args[0])){
+ } else if (args.length > 0 && _.isNumber(args[0])) { //if the argument is numeric (instead of an object) - default it to a PK lookup
var criteria = {};
criteria[self.table.pk] = args[0];
self.where(criteria);
- //if the argument is an object, parse a where statement
- }else if (args.length > 0 && _.isObject(args[0])){
+ } else if (args.length > 0 && _.isObject(args[0])){ //if the argument is an object, parse a where statement
self.where(args[0]);
}
return self;

0 comments on commit 85a6bfd

Please sign in to comment.