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 03b32d74
authored
Jan 22, 2015
by
Mick Hansen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor(sql/where): further integration of new where generator
1 parent
b1f106ca
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
47 additions
and
13 deletions
lib/dialects/abstract/query-generator.js
test/integration/model.test.js
test/unit/sql/where.test.js
lib/dialects/abstract/query-generator.js
View file @
03b32d7
...
...
@@ -1544,10 +1544,11 @@ module.exports = (function() {
var
self
=
this
,
items
=
[];
binding
=
' '
+
(
binding
||
'AND'
)
+
' '
;
binding
=
binding
||
'AND'
;
if
(
binding
.
substr
(
0
,
1
)
!==
' '
)
binding
=
' '
+
binding
+
' '
;
if
(
_
.
isPlainObject
(
where
))
{
_
.
for
I
n
(
where
,
function
(
value
,
key
)
{
_
.
for
Ow
n
(
where
,
function
(
value
,
key
)
{
items
.
push
(
self
.
whereItemQuery
(
key
,
value
,
options
));
});
}
else
{
...
...
@@ -1635,28 +1636,47 @@ module.exports = (function() {
}
}
if
(
value
instanceof
Utils
.
literal
)
{
if
(
value
instanceof
Utils
.
literal
||
value
instanceof
Utils
.
where
)
{
return
this
.
handleSequelizeMethod
(
value
);
}
if
(
key
===
undefined
&&
Array
.
isArray
(
value
))
{
if
(
Utils
.
canTreatArrayAsAnd
(
value
))
{
key
=
'$and'
;
}
else
{
return
Utils
.
format
(
value
,
this
.
dialect
);
}
}
// OR/AND grouping logic
if
(
key
===
'$or'
||
key
===
'$and'
)
{
binding
=
key
===
'$or'
?
'
OR'
:
'AND
'
;
binding
=
key
===
'$or'
?
'
OR '
:
' AND
'
;
if
(
Array
.
isArray
(
value
))
{
return
'('
+
value
.
map
(
function
(
item
)
{
value
=
value
.
map
(
function
(
item
)
{
return
self
.
whereItemsQuery
(
item
,
options
,
binding
);
}).
join
(
' '
+
binding
+
' '
)
+
')'
;
}).
filter
(
function
(
item
)
{
return
item
&&
item
.
length
;
});
return
value
.
length
?
'('
+
value
.
join
(
binding
)
+
')'
:
undefined
;
}
else
{
return
'('
+
self
.
whereItemsQuery
(
value
,
options
,
binding
)
+
')'
;
value
=
self
.
whereItemsQuery
(
value
,
options
,
binding
);
return
value
?
'('
+
value
+
')'
:
undefined
;
}
}
if
(
value
)
{
if
(
value
.
$or
||
value
.
$and
)
{
return
'('
+
value
.
$or
.
map
(
function
(
_value
)
{
return
self
.
whereItemQuery
(
key
,
_value
,
options
);
}).
join
(
value
.
$or
?
' OR '
:
' AND '
)
+
')'
;
binding
=
value
.
$or
?
' OR '
:
' AND '
;
value
=
value
.
$or
.
map
(
function
(
_value
)
{
return
self
.
whereItemQuery
(
key
,
_value
,
options
);
}).
filter
(
function
(
item
)
{
return
item
&&
item
.
length
;
});
return
value
.
length
?
'('
+
value
.
join
(
binding
)
+
')'
:
undefined
;
}
}
...
...
@@ -1745,6 +1765,12 @@ module.exports = (function() {
}
if
(
smth
&&
smth
.
_isSequelizeMethod
===
true
)
{
// Checking a property is cheaper than a lot of instanceof calls
if
(
smth
instanceof
Utils
.
and
||
smth
instanceof
Utils
.
and
)
{
return
self
.
whereItemsQuery
(
smth
,
{
model
:
factory
,
prefix
:
prepend
&&
tableName
});
}
result
=
this
.
handleSequelizeMethod
(
smth
,
tableName
,
factory
,
options
,
prepend
);
}
else
if
(
Utils
.
_
.
isPlainObject
(
smth
))
{
return
self
.
whereItemsQuery
(
smth
,
{
...
...
@@ -1776,7 +1802,6 @@ module.exports = (function() {
result
=
this
.
escape
(
smth
);
}
else
if
(
Array
.
isArray
(
smth
))
{
if
(
smth
.
length
===
0
)
return
'1=1'
;
if
(
Utils
.
canTreatArrayAsAnd
(
smth
))
{
var
_smth
=
self
.
sequelize
.
and
.
apply
(
null
,
smth
);
result
=
self
.
getWhereConditions
(
_smth
,
tableName
,
factory
,
options
,
prepend
);
...
...
test/integration/model.test.js
View file @
03b32d7
...
...
@@ -1366,9 +1366,9 @@ describe(Support.getTestDialectTeaser('Model'), function() {
.
then
(
function
(
pet
)
{
return
pet
.
destroy
();
})
.
then
(
function
()
{
return
[
User
.
find
({
where
:
user
.
id
,
include
:
Pet
}),
User
.
find
({
where
:
{
id
:
user
.
id
}
,
include
:
Pet
}),
User
.
find
({
where
:
user
.
id
,
where
:
{
id
:
user
.
id
}
,
include
:
[{
model
:
Pet
,
paranoid
:
false
}]
})
];
...
...
test/unit/sql/where.test.js
View file @
03b32d7
...
...
@@ -102,6 +102,15 @@ suite('SQL', function() {
});
});
suite
(
'Buffer'
,
function
()
{
testsql
(
'field'
,
new
Buffer
(
'Sequelize'
),
{
postgres
:
'"field" = E\'\\\\x53657175656c697a65\''
,
sqlite
:
"`field` = X'53657175656c697a65'"
,
mysql
:
"`field` = X'53657175656c697a65'"
,
mssql
:
"[field] = 0x'53657175656c697a65'"
});
});
suite
(
'$not'
,
function
()
{
testsql
(
'deleted'
,
{
$not
:
true
...
...
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