Fix issue with a where object with more than one member

This commit is contained in:
Timothy Warren 2014-10-30 11:08:00 -04:00
parent 439630cdda
commit e4c62ef3e7
2 changed files with 12 additions and 3 deletions

View File

@ -187,7 +187,7 @@ var QueryBuilder = function(driver, adapter) {
_p.mixedSet('whereMap', 'both', args.key, args.val); _p.mixedSet('whereMap', 'both', args.key, args.val);
_p.mixedSet('whereValues', 'value', args.key, args.val); _p.mixedSet('whereValues', 'value', args.key, args.val);
}, },
where: function(key, val, conj) { where: function(key, val, defaultConj) {
// Normalize key and value and insert into state.whereMap // Normalize key and value and insert into state.whereMap
_p.whereMixedSet(key, val); _p.whereMixedSet(key, val);
@ -205,7 +205,8 @@ var QueryBuilder = function(driver, adapter) {
lastItem = state.queryMap[state.queryMap.length - 1]; lastItem = state.queryMap[state.queryMap.length - 1];
// Determine the correct conjunction // Determine the correct conjunction
if (state.queryMap.length < 1 || firstItem.conjunction.contains('JOIN')) var conj = defaultConj;
if (state.queryMap.length === 0 || firstItem.conjunction.contains('JOIN'))
{ {
conj = " WHERE "; conj = " WHERE ";
} }
@ -280,6 +281,7 @@ var QueryBuilder = function(driver, adapter) {
vals = state.values.concat(state.whereValues); vals = state.values.concat(state.whereValues);
} }
//console.log(state.queryMap);
//console.log(sql); //console.log(sql);
//console.log(vals); //console.log(vals);
//console.log('------------------------'); //console.log('------------------------');
@ -781,7 +783,7 @@ var QueryBuilder = function(driver, adapter) {
* @param {String} table - The table to insert into * @param {String} table - The table to insert into
* @param {Array} data - The array of objects containing data rows to insert * @param {Array} data - The array of objects containing data rows to insert
* @param {Function} callback - Callback for handling database response * @param {Function} callback - Callback for handling database response
* @example query.insertBatch('foo',[{id:1,val:'bar'},{id:2,val:'baz'}], callbackFunction);S * @example query.insertBatch('foo',[{id:1,val:'bar'},{id:2,val:'baz'}], callbackFunction);
* @return void * @return void
*/ */
this.insertBatch = function(/* table, data, callback */) { this.insertBatch = function(/* table, data, callback */) {

View File

@ -377,6 +377,13 @@ module.exports = (function QueryBuilderTestBase() {
test.expect(1); test.expect(1);
base.qb.where('id', 5) base.qb.where('id', 5)
.delete('create_test', base.testCallback.bind(this, test)); .delete('create_test', base.testCallback.bind(this, test));
},
'Delete multiple where values': function(test) {
test.expect(1);
base.qb.delete('create_test', {
id: 5,
key: 'gogle'
}, base.testCallback.bind(this, test));
} }
}, },
// ! Get compiled tests // ! Get compiled tests