Comparing version 0.6.1 to 0.6.2
@@ -187,3 +187,3 @@ (function(exports) { | ||
if( Array.isArray( wh ) ) { | ||
if( Array.isArray( wh ) && Object(wh[0]) === wh[0] ) { | ||
wh.forEach(function(v, k, arr) { | ||
@@ -197,2 +197,6 @@ arr[k] = this.stringify( v ).join(' AND '); | ||
else if( Array.isArray(wh) ) { | ||
wh = wh.join(' OR '); | ||
} | ||
else if( wh === Object(wh) ) { | ||
@@ -203,8 +207,2 @@ // stringify the where statements | ||
// else { | ||
// if( opt.backquote ) { | ||
// wh = this.backquote(wh); | ||
// } | ||
// } | ||
// else wh is a string | ||
@@ -363,7 +361,3 @@ | ||
if( typeof p === 'undefined' ) { | ||
this.where( ' NOT', '' ); | ||
} | ||
else if( Array.isArray(p) && Object(p[0]) === p[0] ) { | ||
if( Array.isArray(p) && Object(p[0]) === p[0] ) { | ||
this.where( p.map(function(v, k) { | ||
@@ -377,2 +371,3 @@ return this.stringify(v, '!=') | ||
} | ||
else if( Object(p) === p ) { | ||
@@ -382,2 +377,6 @@ this.where( this.stringify(p, '!=').join(sep) ); | ||
else { | ||
this.where( ' NOT', '' ); | ||
} | ||
return this; | ||
@@ -406,13 +405,18 @@ }; | ||
if( ! Array.isArray(p) && Object(p) !== p ) { | ||
this.condition.call( this, this.format(p), eq ); | ||
this.condition = this.condition || this.where; | ||
if( Array.isArray(p) && Object(p[0]) === p[0] ) { | ||
sep = sep.trim() | ||
this.condition.call( this, p.map(function(val) { | ||
var str = this.stringify( val, eq ).join(' AND '); | ||
return str; | ||
// this.condition.call( this, str, sep ); | ||
}.bind(this)), sep ); | ||
} | ||
// else if( Array.isArray(p) && Object(p[0]) === p[0] ) { | ||
// this.condition.call( this, p.map(function(val, k) { | ||
// return this.stringify(val, eq).join(sep) | ||
// }.bind(this)) ); | ||
// } | ||
else { | ||
else if( Object(p) === p ) { | ||
this.condition.call( this, this.stringify( p, eq ).join(sep) ); | ||
} | ||
else { | ||
this.condition.call( this, this.format(p), eq ); | ||
} | ||
@@ -419,0 +423,0 @@ return this; |
{ | ||
"name": "monologue", | ||
"version": "0.6.1", | ||
"version": "0.6.2", | ||
"description": "Streamlined MySQL query building", | ||
@@ -5,0 +5,0 @@ "main": "./monologue.js", |
@@ -60,13 +60,13 @@ Monologue - Streamlined query building | ||
// SELECT * FROM `posts` WHERE `favorited` <= 815 | ||
// SELECT * FROM `posts` WHERE `favorited` <= 815 AND `commentors` <= 1516 OR `likes` <= 42 | ||
mono() | ||
.select('*', 'posts') | ||
.where('favorited').lte(815) | ||
.lte([{favorited: 815, commentors: 1516},{likes: 42}], 'OR') | ||
.query().sql; | ||
// SELECT `post_id`, `comments` FROM `comments` WHERE `post_id` = 23565 AND date_time > \'2015-12-01 00:00:00\' | ||
mono() | ||
.select(['post_id', 'comments'], 'comments') | ||
.where({post_id: 23565}) | ||
.where('date_time').gt('2015-12-01 00:00:00') | ||
mono() | ||
.select(['post_id', 'comments'], 'comments') | ||
.where({post_id: 23565}) | ||
.where('date_time').gt('2015-12-01 00:00:00') | ||
@@ -73,0 +73,0 @@ // SELECT sum(id) as count FROM comments HAVING count >= 42 |
56344
491