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

Commit 4efa2a64 by calvintwr

$not as grouping comparator

1 parent 09d982ac
...@@ -1567,6 +1567,7 @@ module.exports = (function() { ...@@ -1567,6 +1567,7 @@ module.exports = (function() {
var self = this var self = this
, binding , binding
, outerBinding
, comparatorMap , comparatorMap
, aliasMap , aliasMap
, comparator = '=' , comparator = '='
...@@ -1652,9 +1653,14 @@ module.exports = (function() { ...@@ -1652,9 +1653,14 @@ module.exports = (function() {
} }
} }
// OR/AND grouping logic // OR/AND/NOT grouping logic
if (key === '$or' || key === '$and') { if (key === '$or' || key === '$and' || key === '$not') {
binding = key === '$or' ? ' OR ' : ' AND ';
binding = (key === '$or') ?' OR ' : ' AND ';
outerBinding = '';
if (key === '$not') outerBinding = 'NOT ';
if (Array.isArray(value)) { if (Array.isArray(value)) {
value = value.map(function (item) { value = value.map(function (item) {
...@@ -1667,10 +1673,10 @@ module.exports = (function() { ...@@ -1667,10 +1673,10 @@ module.exports = (function() {
return item && item.length; return item && item.length;
}); });
return value.length ? '('+value.join(binding)+')' : undefined; return value.length ? outerBinding + '('+value.join(binding)+')' : undefined;
} else { } else {
value = self.whereItemsQuery(value, options, binding); value = self.whereItemsQuery(value, options, binding);
return value ? '('+value+')' : undefined; return value ? outerBinding + '('+value+')' : undefined;
} }
} }
......
...@@ -159,7 +159,7 @@ suite(Support.getTestDialectTeaser('SQL'), function() { ...@@ -159,7 +159,7 @@ suite(Support.getTestDialectTeaser('SQL'), function() {
}); });
}); });
suite('$and/$or', function () { suite('$and/$or/$not', function () {
suite('$or', function () { suite('$or', function () {
testsql('email', { testsql('email', {
$or: ['maker@mhansen.io', 'janzeh@gmail.com'] $or: ['maker@mhansen.io', 'janzeh@gmail.com']
...@@ -231,6 +231,18 @@ suite(Support.getTestDialectTeaser('SQL'), function() { ...@@ -231,6 +231,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 () { suite('$gt', function () {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!