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 15153227
authored
Jul 10, 2013
by
Sascha Depold
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'milestones/2.0.0' of github.com:sequelize/sequelize into milestones/2.0.0
2 parents
ef5bfd20
ce9dbd79
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
305 additions
and
10 deletions
lib/dialects/mysql/query-generator.js
lib/dialects/postgres/query-generator.js
spec/dao-factory.spec.js
lib/dialects/mysql/query-generator.js
View file @
1515322
...
@@ -431,11 +431,24 @@ module.exports = (function() {
...
@@ -431,11 +431,24 @@ module.exports = (function() {
result
.
push
([
_key
,
_value
].
join
(
" IN "
))
result
.
push
([
_key
,
_value
].
join
(
" IN "
))
}
else
if
((
value
)
&&
(
typeof
value
==
'object'
)
&&
!
(
value
instanceof
Date
))
{
}
else
if
((
value
)
&&
(
typeof
value
==
'object'
)
&&
!
(
value
instanceof
Date
))
{
// is value an object?
if
(
!!
value
.
join
)
{
//using as sentinel for join column => value
//using as sentinel for join column => value
_value
=
this
.
quoteIdentifiers
(
value
.
join
)
_value
=
this
.
quoteIdentifiers
(
value
.
join
)
result
.
push
([
_key
,
_value
].
join
(
"="
))
result
.
push
([
_key
,
_value
].
join
(
"="
))
}
else
{
for
(
var
logic
in
value
)
{
var
logicResult
=
this
.
getWhereLogic
(
logic
)
if
(
logicResult
===
"BETWEEN"
||
logicResult
===
"NOT BETWEEN"
)
{
_value
=
this
.
escape
(
value
[
logic
][
0
])
var
_value2
=
this
.
escape
(
value
[
logic
][
1
])
result
.
push
(
' ('
+
_key
+
' '
+
logicResult
+
' '
+
_value
+
' AND '
+
_value2
+
') '
)
}
else
{
_value
=
this
.
escape
(
value
[
logic
])
result
.
push
([
_key
,
_value
].
join
(
' '
+
logicResult
+
' '
))
}
}
}
}
else
{
}
else
{
_value
=
this
.
escape
(
value
)
_value
=
this
.
escape
(
value
)
result
.
push
((
_value
==
'NULL'
)
?
_key
+
" IS NULL"
:
[
_key
,
_value
].
join
(
"="
))
result
.
push
((
_value
==
'NULL'
)
?
_key
+
" IS NULL"
:
[
_key
,
_value
].
join
(
"="
))
...
@@ -445,6 +458,33 @@ module.exports = (function() {
...
@@ -445,6 +458,33 @@ module.exports = (function() {
return
result
.
join
(
" AND "
)
return
result
.
join
(
" AND "
)
},
},
getWhereLogic
:
function
(
logic
)
{
switch
(
logic
)
{
case
'gte'
:
return
'>='
break
case
'gt'
:
return
'>'
break
case
'lte'
:
return
'<='
break
case
'lt'
:
return
'<'
break
case
'ne'
:
return
'!='
break
case
'between'
:
return
'BETWEEN'
break
case
'nbetween'
:
case
'notbetween'
:
return
'NOT BETWEEN'
break
}
},
attributesToSQL
:
function
(
attributes
)
{
attributesToSQL
:
function
(
attributes
)
{
var
result
=
{}
var
result
=
{}
...
...
lib/dialects/postgres/query-generator.js
View file @
1515322
...
@@ -522,9 +522,24 @@ module.exports = (function() {
...
@@ -522,9 +522,24 @@ module.exports = (function() {
result
.
push
([
_key
,
_value
].
join
(
" IN "
))
result
.
push
([
_key
,
_value
].
join
(
" IN "
))
}
}
else
if
((
value
)
&&
(
typeof
value
===
"object"
))
{
else
if
((
value
)
&&
(
typeof
value
===
"object"
))
{
//using as sentinel for join column => value
if
(
!!
value
.
join
)
{
_value
=
this
.
quoteIdentifiers
(
value
.
join
)
//using as sentinel for join column => value
result
.
push
([
_key
,
_value
].
join
(
"="
))
_value
=
this
.
quoteIdentifiers
(
value
.
join
)
result
.
push
([
_key
,
_value
].
join
(
"="
))
}
else
{
for
(
var
logic
in
value
)
{
var
logicResult
=
this
.
getWhereLogic
(
logic
)
if
(
logicResult
===
"BETWEEN"
||
logicResult
===
"NOT BETWEEN"
)
{
_value
=
this
.
escape
(
value
[
logic
][
0
])
var
_value2
=
this
.
escape
(
value
[
logic
][
1
])
result
.
push
(
' ('
+
_key
+
' '
+
logicResult
+
' '
+
_value
+
' AND '
+
_value2
+
') '
)
}
else
{
_value
=
this
.
escape
(
value
[
logic
])
result
.
push
([
_key
,
_value
].
join
(
' '
+
logicResult
+
' '
))
}
}
}
}
else
{
}
else
{
_value
=
this
.
escape
(
value
)
_value
=
this
.
escape
(
value
)
result
.
push
((
_value
==
'NULL'
)
?
_key
+
" IS NULL"
:
[
_key
,
_value
].
join
(
"="
))
result
.
push
((
_value
==
'NULL'
)
?
_key
+
" IS NULL"
:
[
_key
,
_value
].
join
(
"="
))
...
@@ -534,6 +549,33 @@ module.exports = (function() {
...
@@ -534,6 +549,33 @@ module.exports = (function() {
return
result
.
join
(
' AND '
)
return
result
.
join
(
' AND '
)
},
},
getWhereLogic
:
function
(
logic
)
{
switch
(
logic
)
{
case
'gte'
:
return
'>='
break
case
'gt'
:
return
'>'
break
case
'lte'
:
return
'<='
break
case
'lt'
:
return
'<'
break
case
'ne'
:
return
'!='
break
case
'between'
:
return
'BETWEEN'
break
case
'nbetween'
:
case
'notbetween'
:
return
'NOT BETWEEN'
break
}
},
attributesToSQL
:
function
(
attributes
)
{
attributesToSQL
:
function
(
attributes
)
{
var
result
=
{}
var
result
=
{}
...
...
spec/dao-factory.spec.js
View file @
1515322
...
@@ -18,7 +18,9 @@ describe(Helpers.getTestDialectTeaser("DAOFactory"), function() {
...
@@ -18,7 +18,9 @@ describe(Helpers.getTestDialectTeaser("DAOFactory"), function() {
this
.
User
=
sequelize
.
define
(
'User'
,
{
this
.
User
=
sequelize
.
define
(
'User'
,
{
username
:
DataTypes
.
STRING
,
username
:
DataTypes
.
STRING
,
secretValue
:
DataTypes
.
STRING
,
secretValue
:
DataTypes
.
STRING
,
data
:
DataTypes
.
STRING
data
:
DataTypes
.
STRING
,
intVal
:
DataTypes
.
INTEGER
,
theDate
:
DataTypes
.
DATE
})
})
}.
bind
(
this
),
}.
bind
(
this
),
onComplete
:
function
()
{
onComplete
:
function
()
{
...
@@ -807,7 +809,8 @@ describe(Helpers.getTestDialectTeaser("DAOFactory"), function() {
...
@@ -807,7 +809,8 @@ describe(Helpers.getTestDialectTeaser("DAOFactory"), function() {
,
User
=
this
.
sequelize
.
define
(
'ParanoidUser'
,
{
,
User
=
this
.
sequelize
.
define
(
'ParanoidUser'
,
{
username
:
Sequelize
.
STRING
,
username
:
Sequelize
.
STRING
,
secretValue
:
Sequelize
.
STRING
,
secretValue
:
Sequelize
.
STRING
,
data
:
Sequelize
.
STRING
data
:
Sequelize
.
STRING
,
intVal
:
{
type
:
Sequelize
.
INTEGER
,
defaultValue
:
1
}
},
{
},
{
paranoid
:
true
paranoid
:
true
})
})
...
@@ -842,6 +845,216 @@ describe(Helpers.getTestDialectTeaser("DAOFactory"), function() {
...
@@ -842,6 +845,216 @@ describe(Helpers.getTestDialectTeaser("DAOFactory"), function() {
})
// - destroy
})
// - destroy
describe
(
'special where conditions'
,
function
()
{
before
(
function
(
done
)
{
var
self
=
this
this
.
User
.
create
({
username
:
'boo'
,
intVal
:
5
,
theDate
:
'2013-01-01 12:00'
}).
success
(
function
(
user
){
self
.
user
=
user
self
.
User
.
create
({
username
:
'boo2'
,
intVal
:
10
,
theDate
:
'2013-01-10 12:00'
}).
success
(
function
(
user2
){
self
.
user2
=
user2
done
()
})
})
})
it
(
'should be able to find a row between a certain date'
,
function
(
done
)
{
this
.
User
.
findAll
({
where
:
{
theDate
:
{
between
:
[
'2013-01-02'
,
'2013-01-11'
]
}
}
}).
success
(
function
(
users
)
{
expect
(
users
[
0
].
username
).
toEqual
(
'boo2'
)
expect
(
users
[
0
].
intVal
).
toEqual
(
10
)
done
()
})
})
it
(
'should be able to find a row between a certain date and an additional where clause'
,
function
(
done
)
{
this
.
User
.
findAll
({
where
:
{
theDate
:
{
between
:
[
'2013-01-02'
,
'2013-01-11'
]
},
intVal
:
10
}
}).
success
(
function
(
users
)
{
expect
(
users
[
0
].
username
).
toEqual
(
'boo2'
)
expect
(
users
[
0
].
intVal
).
toEqual
(
10
)
done
()
})
})
it
(
'should be able to find a row not between a certain integer'
,
function
(
done
)
{
this
.
User
.
findAll
({
where
:
{
intVal
:
{
nbetween
:
[
8
,
10
]
}
}
}).
success
(
function
(
users
)
{
expect
(
users
[
0
].
username
).
toEqual
(
'boo'
)
expect
(
users
[
0
].
intVal
).
toEqual
(
5
)
done
()
})
})
it
(
'should be able to find a row using not between and between logic'
,
function
(
done
)
{
this
.
User
.
findAll
({
where
:
{
theDate
:
{
between
:
[
'2012-12-10'
,
'2013-01-02'
],
nbetween
:
[
'2013-01-04'
,
'2013-01-20'
]
}
}
}).
success
(
function
(
users
)
{
expect
(
users
[
0
].
username
).
toEqual
(
'boo'
)
expect
(
users
[
0
].
intVal
).
toEqual
(
5
)
done
()
})
})
it
(
'should be able to find a row using not between and between logic with dates'
,
function
(
done
)
{
this
.
User
.
findAll
({
where
:
{
theDate
:
{
between
:
[
new
Date
(
'2012-12-10'
),
new
Date
(
'2013-01-02'
)],
nbetween
:
[
new
Date
(
'2013-01-04'
),
new
Date
(
'2013-01-20'
)]
}
}
}).
success
(
function
(
users
)
{
expect
(
users
[
0
].
username
).
toEqual
(
'boo'
)
expect
(
users
[
0
].
intVal
).
toEqual
(
5
)
done
()
})
})
it
(
'should be able to find a row using greater than or equal to logic with dates'
,
function
(
done
)
{
this
.
User
.
findAll
({
where
:
{
theDate
:
{
gte
:
new
Date
(
'2013-01-09'
)
}
}
}).
success
(
function
(
users
)
{
expect
(
users
[
0
].
username
).
toEqual
(
'boo2'
)
expect
(
users
[
0
].
intVal
).
toEqual
(
10
)
done
()
})
})
it
(
'should be able to find a row using greater than or equal to'
,
function
(
done
)
{
this
.
User
.
find
({
where
:
{
intVal
:
{
gte
:
6
}
}
}).
success
(
function
(
user
)
{
expect
(
user
.
username
).
toEqual
(
'boo2'
)
expect
(
user
.
intVal
).
toEqual
(
10
)
done
()
})
})
it
(
'should be able to find a row using greater than'
,
function
(
done
)
{
this
.
User
.
find
({
where
:
{
intVal
:
{
gt
:
5
}
}
}).
success
(
function
(
user
)
{
expect
(
user
.
username
).
toEqual
(
'boo2'
)
expect
(
user
.
intVal
).
toEqual
(
10
)
done
()
})
})
it
(
'should be able to find a row using lesser than or equal to'
,
function
(
done
)
{
this
.
User
.
find
({
where
:
{
intVal
:
{
lte
:
5
}
}
}).
success
(
function
(
user
)
{
expect
(
user
.
username
).
toEqual
(
'boo'
)
expect
(
user
.
intVal
).
toEqual
(
5
)
done
()
})
})
it
(
'should be able to find a row using lesser than'
,
function
(
done
)
{
this
.
User
.
find
({
where
:
{
intVal
:
{
lt
:
6
}
}
}).
success
(
function
(
user
)
{
expect
(
user
.
username
).
toEqual
(
'boo'
)
expect
(
user
.
intVal
).
toEqual
(
5
)
done
()
})
})
it
(
'should have no problem finding a row using lesser and greater than'
,
function
(
done
)
{
this
.
User
.
findAll
({
where
:
{
intVal
:
{
lt
:
6
,
gt
:
4
}
}
}).
success
(
function
(
users
)
{
expect
(
users
[
0
].
username
).
toEqual
(
'boo'
)
expect
(
users
[
0
].
intVal
).
toEqual
(
5
)
done
()
})
})
it
(
'should be able to find a row using not equal to logic'
,
function
(
done
)
{
this
.
User
.
find
({
where
:
{
intVal
:
{
ne
:
10
}
}
}).
success
(
function
(
user
)
{
expect
(
user
.
username
).
toEqual
(
'boo'
)
expect
(
user
.
intVal
).
toEqual
(
5
)
done
()
})
})
it
(
'should be able to find multiple users with any of the special where logic properties'
,
function
(
done
)
{
this
.
User
.
findAll
({
where
:
{
intVal
:
{
lte
:
10
}
}
}).
success
(
function
(
users
)
{
expect
(
users
[
0
].
username
).
toEqual
(
'boo'
)
expect
(
users
[
0
].
intVal
).
toEqual
(
5
)
expect
(
users
[
1
].
username
).
toEqual
(
'boo2'
)
expect
(
users
[
1
].
intVal
).
toEqual
(
10
)
done
()
})
})
})
describe
(
'find'
,
function
find
()
{
describe
(
'find'
,
function
find
()
{
before
(
function
(
done
)
{
before
(
function
(
done
)
{
this
.
User
.
create
({
this
.
User
.
create
({
...
...
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