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 bebad6e2
authored
Jun 15, 2015
by
Mick Hansen
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3933 from ns3777k/hotfix/and-or-shorten-syntax
fix fields and-or logic
2 parents
878841b0
650a85d3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
10 deletions
lib/dialects/abstract/query-generator.js
test/unit/sql/where.test.js
lib/dialects/abstract/query-generator.js
View file @
bebad6e
...
...
@@ -1789,18 +1789,24 @@ var QueryGenerator = {
}
}
if
(
value
)
{
if
(
value
.
$or
||
value
.
$and
)
{
binding
=
value
.
$or
?
' OR '
:
' AND '
;
if
(
value
&&
(
value
.
$or
||
value
.
$and
)
)
{
binding
=
value
.
$or
?
' OR '
:
' AND '
;
value
=
value
.
$or
||
value
.
$and
;
value
=
(
value
.
$or
||
value
.
$and
).
map
(
function
(
_value
)
{
return
self
.
whereItemQuery
(
key
,
_value
,
options
);
}).
filter
(
function
(
item
)
{
return
item
&&
item
.
length
;
});
return
value
.
length
?
'('
+
value
.
join
(
binding
)
+
')'
:
undefined
;
if
(
_
.
isPlainObject
(
value
))
{
value
=
_
.
reduce
(
value
,
function
(
result
,
_value
,
key
)
{
result
.
push
(
_
.
zipObject
([
key
],
[
_value
]));
return
result
;
},
[]);
}
value
=
value
.
map
(
function
(
_value
)
{
return
self
.
whereItemQuery
(
key
,
_value
,
options
);
}).
filter
(
function
(
item
)
{
return
item
&&
item
.
length
;
});
return
value
.
length
?
'('
+
value
.
join
(
binding
)
+
')'
:
undefined
;
}
if
(
_
.
isPlainObject
(
value
)
&&
fieldType
instanceof
DataTypes
.
JSON
&&
options
.
json
!==
false
)
{
...
...
test/unit/sql/where.test.js
View file @
bebad6e
...
...
@@ -186,6 +186,15 @@ suite(Support.getTestDialectTeaser('SQL'), function() {
default
:
'([email] = \'maker@mhansen.io\' OR [email] = \'janzeh@gmail.com\')'
});
testsql
(
'rank'
,
{
$or
:
{
$lt
:
100
,
$eq
:
null
}
},
{
default
:
'([rank] < 100 OR [rank] IS NULL)'
});
testsql
(
'$or'
,
[
{
email
:
'maker@mhansen.io'
},
{
email
:
'janzeh@gmail.com'
}
...
...
@@ -259,6 +268,15 @@ suite(Support.getTestDialectTeaser('SQL'), function() {
default
:
"([name] LIKE '%hello' AND [name] LIKE 'hello%')"
});
testsql
(
'rank'
,
{
$and
:
{
$ne
:
15
,
$between
:
[
10
,
20
]
}
},
{
default
:
'([rank] != 15 AND [rank] BETWEEN 10 AND 20)'
});
testsql
(
'name'
,
{
$and
:
[
{
like
:
'%someValue1%'
},
...
...
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