Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
public
/
sequelize
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
不要怂,就是干,撸起袖子干!
Commit 4efa2a64
authored
Mar 15, 2015
by
calvintwr
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
$not as grouping comparator
1 parent
09d982ac
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
6 deletions
lib/dialects/abstract/query-generator.js
test/unit/sql/where.test.js
lib/dialects/abstract/query-generator.js
View file @
4efa2a6
...
@@ -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
;
}
}
}
}
...
...
test/unit/sql/where.test.js
View file @
4efa2a6
...
@@ -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
()
{
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment