Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

支持操作符的条件,如like、大于、小于等 #61

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/operator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('?? = ?');
}
Expand Down
2 changes: 2 additions & 0 deletions test/operator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});

Expand Down