diff --git a/lib/operator.js b/lib/operator.js index 51bf65a..a3610b4 100644 --- a/lib/operator.js +++ b/lib/operator.js @@ -316,12 +316,15 @@ proto._where = function(where) { const wheres = []; const values = []; for (const key in where) { - const value = where[key]; + let value = where[key]; if (Array.isArray(value)) { wheres.push('?? IN (?)'); } else { if (value === null || value === undefined) { wheres.push('?? IS ?'); + } else if (value && value.operator) { + wheres.push('?? ' + value.operator + ' ?'); + value = value.value; } else { wheres.push('?? = ?'); } diff --git a/test/operator.test.js b/test/operator.test.js index d39d00a..c71dc5b 100644 --- a/test/operator.test.js +++ b/test/operator.test.js @@ -25,6 +25,8 @@ describe('operator.test.js', function() { assert.equal(op._where({ id: 1, name: 'foo\'\"' }), ' WHERE `id` = 1 AND `name` = \'foo\\\'\\\"\''); assert.equal(op._where({ id: 1, name: 'foo\'\"', user: 'fengmk2' }), ' WHERE `id` = 1 AND `name` = \'foo\\\'\\\"\' AND `user` = \'fengmk2\''); + assert.equal(op._where({ name: { operator: 'like', value: '%wvv8oo%' } }), ' WHERE `name` like \'%wvv8oo%\''); + assert.equal(op._where({ age: { operator: '>', value: 10 } }), ' WHERE `age` > 10'); }); });