不要怂,就是干,撸起袖子干!

You need to sign in or sign up before continuing.
Commit 1c10d07e by Mick Hansen

Merge pull request #3351 from calvintwr/master

$not as grouping comparator
2 parents 16d175a1 4efa2a64
......@@ -1583,6 +1583,7 @@ module.exports = (function() {
var self = this
, binding
, outerBinding
, comparatorMap
, aliasMap
, comparator = '='
......@@ -1668,9 +1669,14 @@ module.exports = (function() {
}
}
// OR/AND grouping logic
if (key === '$or' || key === '$and') {
binding = key === '$or' ? ' OR ' : ' AND ';
// OR/AND/NOT grouping logic
if (key === '$or' || key === '$and' || key === '$not') {
binding = (key === '$or') ?' OR ' : ' AND ';
outerBinding = '';
if (key === '$not') outerBinding = 'NOT ';
if (Array.isArray(value)) {
value = value.map(function (item) {
......@@ -1683,10 +1689,10 @@ module.exports = (function() {
return item && item.length;
});
return value.length ? '('+value.join(binding)+')' : undefined;
return value.length ? outerBinding + '('+value.join(binding)+')' : undefined;
} else {
value = self.whereItemsQuery(value, options, binding);
return value ? '('+value+')' : undefined;
return value ? outerBinding + '('+value+')' : undefined;
}
}
......
......@@ -161,7 +161,7 @@ suite(Support.getTestDialectTeaser('SQL'), function() {
});
});
suite('$and/$or', function () {
suite('$and/$or/$not', function () {
suite('$or', function () {
testsql('email', {
$or: ['maker@mhansen.io', 'janzeh@gmail.com']
......@@ -257,6 +257,18 @@ suite(Support.getTestDialectTeaser('SQL'), function() {
});
});
});
suite('$not', function () {
testsql('$not', {
shared: 1,
$or: {
group_id: 1,
user_id: 2
}
}, {
default: "NOT ([shared] = 1 AND ([group_id] = 1 OR [user_id] = 2))"
});
});
});
suite('$gt', function () {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!