Skip to content

Commit

Permalink
Fix bug with updating/inserting a null value.
Browse files Browse the repository at this point in the history
  • Loading branch information
Twipped committed Sep 27, 2015
1 parent 89bb8ce commit 1fed3f5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/mutators.js
Original file line number Diff line number Diff line change
Expand Up @@ -929,9 +929,9 @@ query.set = function set (clause, value, modifier) {
}

// if we received a value, create a set clause
if (isDefined(value)) {
if (typeof value !== 'undefined') {
var column = clause;
if (typeof value === 'object' && typeof value.raw === 'string') {
if (value && typeof value === 'object' && typeof value.raw === 'string') {
clause = clause + ' = ' + value.raw;
} else {
if (!isValidPrimative(value)) {
Expand Down
17 changes: 17 additions & 0 deletions tests/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,5 +171,22 @@ exports['update with object where clause'] = function (test) {
data: [1]
});

test.done();
};

exports['update with a null value'] = function (test) {
var q = queryize().update().database('test', 'users', 'u');

q.set({
firstname: 'bob',
lastname: null
});
q.where('name', null);

test.deepEqual(q.compile(), {
query: 'UPDATE `test`.`users` u SET firstname = ?, lastname = NULL WHERE name = NULL',
data: ['bob']
});

test.done();
};

0 comments on commit 1fed3f5

Please sign in to comment.