Comparing version 0.2.3 to 0.2.4
@@ -14,3 +14,4 @@ (function() { | ||
limit: '', | ||
last: '' | ||
last: '', | ||
columns: null | ||
}; | ||
@@ -309,15 +310,13 @@ | ||
s = ( typeof s === "undefined" ? "=" : s ); | ||
var c = [], | ||
type = toString.call( p ); | ||
var c = []; | ||
if( type === "[object Array]" ) { | ||
if( Array.isArray( p ) ) { | ||
// grab the column names from the first object | ||
global.columns = Object.keys( p[0] ).sort(); | ||
for( var ii = 0, l = p.length; ii < l; ++ii ) { | ||
// if parent is an array and child is an object, | ||
// generate an encapsulated list of values (for inserts) | ||
if( toString.call( p[ii] ) === "[object Object]" ) { | ||
// if "c" is empty, push actual column names | ||
if( c.length === 0 ) c.push( Object.keys( p[ii] ) ); | ||
c.push( global.columns ); | ||
c.push( "(" + this.stringify( p[ii], "" ) + ")"); | ||
@@ -327,3 +326,2 @@ } | ||
else { | ||
// generate a comma-separated list of fields | ||
@@ -336,9 +334,10 @@ c.push( this.format( p[ii], ii, "" ) ); | ||
else { | ||
for( var jj in p ) { | ||
if( toString.call( p[jj] ) === "[object Array]" ) { | ||
c.push( jj + " IN (" + this.stringify( p[jj] ) + ")" ); | ||
var col = global.columns || Object.keys( p ).sort(); | ||
for( var jj = 0, len = col.length; jj < len; ++jj ) { | ||
if( Array.isArray( p[col[jj]] ) ) { | ||
c.push( col[jj] + " IN (" + this.stringify( p[col[jj]] ) + ")" ); | ||
} | ||
else { | ||
c.push( this.format( p[jj], jj, s ) ); | ||
c.push( this.format( p[col[jj]], col[jj], s ) ); | ||
} | ||
@@ -345,0 +344,0 @@ } |
{ | ||
"name": "monologue", | ||
"version": "0.2.3", | ||
"version": "0.2.4", | ||
"description": "Streamlined MySQL query building", | ||
@@ -5,0 +5,0 @@ "main": "./monologue.js", |
12877
287