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 1c562924
authored
May 02, 2013
by
durango
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #583 from durango/master
Min/Max decimal support closes #579
2 parents
a1c06dd7
92bb5fe2
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
4 deletions
lib/dao-factory.js
lib/query-interface.js
spec/dao-factory.spec.js
lib/dao-factory.js
View file @
1c56292
...
...
@@ -271,14 +271,14 @@ module.exports = (function() {
DAOFactory
.
prototype
.
max
=
function
(
field
,
options
)
{
options
=
Utils
.
_
.
extend
({
attributes
:
[]
},
options
||
{})
options
.
attributes
.
push
([
'max('
+
field
+
')'
,
'max'
])
options
.
parse
In
t
=
true
options
.
parse
Floa
t
=
true
return
this
.
QueryInterface
.
rawSelect
(
this
.
getTableName
(),
options
,
'max'
)
}
DAOFactory
.
prototype
.
min
=
function
(
field
,
options
)
{
options
=
Utils
.
_
.
extend
({
attributes
:
[]
},
options
||
{})
options
.
attributes
.
push
([
'min('
+
field
+
')'
,
'min'
])
options
.
parse
In
t
=
true
options
.
parse
Floa
t
=
true
return
this
.
QueryInterface
.
rawSelect
(
this
.
getTableName
(),
options
,
'min'
)
}
...
...
lib/query-interface.js
View file @
1c56292
...
...
@@ -296,6 +296,10 @@ module.exports = (function() {
result
=
parseInt
(
result
)
}
if
(
options
&&
options
.
parseFloat
)
{
result
=
parseFloat
(
result
)
}
self
.
emit
(
'rawSelect'
,
null
)
emitter
.
emit
(
'success'
,
result
)
})
...
...
spec/dao-factory.spec.js
View file @
1c56292
...
...
@@ -1031,7 +1031,13 @@ describe(Helpers.getTestDialectTeaser("DAOFactory"), function() {
age
:
Sequelize
.
INTEGER
})
this
.
UserWithAge
.
sync
({
force
:
true
}).
success
(
done
)
this
.
UserWithDec
=
this
.
sequelize
.
define
(
'UserWithDec'
,
{
value
:
Sequelize
.
DECIMAL
(
10
,
3
)
})
this
.
UserWithAge
.
sync
({
force
:
true
}).
success
(
function
(){
this
.
UserWithDec
.
sync
({
force
:
true
}).
success
(
done
)
}.
bind
(
this
))
})
it
(
"should return the min value"
,
function
(
done
)
{
...
...
@@ -1052,6 +1058,17 @@ describe(Helpers.getTestDialectTeaser("DAOFactory"), function() {
done
()
})
})
it
(
"should allow decimals in min"
,
function
(
done
){
this
.
UserWithDec
.
create
({
value
:
3.5
}).
success
(
function
(){
this
.
UserWithDec
.
create
({
value
:
5.5
}).
success
(
function
(){
this
.
UserWithDec
.
min
(
'value'
).
success
(
function
(
min
){
expect
(
min
).
toEqual
(
3.5
)
done
()
})
}.
bind
(
this
))
}.
bind
(
this
))
})
})
//- describe: min
describe
(
'max'
,
function
()
{
...
...
@@ -1060,7 +1077,13 @@ describe(Helpers.getTestDialectTeaser("DAOFactory"), function() {
age
:
Sequelize
.
INTEGER
})
this
.
UserWithAge
.
sync
({
force
:
true
}).
success
(
done
)
this
.
UserWithDec
=
this
.
sequelize
.
define
(
'UserWithDec'
,
{
value
:
Sequelize
.
DECIMAL
(
10
,
3
)
})
this
.
UserWithAge
.
sync
({
force
:
true
}).
success
(
function
(){
this
.
UserWithDec
.
sync
({
force
:
true
}).
success
(
done
)
}.
bind
(
this
))
})
it
(
"should return the max value"
,
function
(
done
)
{
...
...
@@ -1074,6 +1097,17 @@ describe(Helpers.getTestDialectTeaser("DAOFactory"), function() {
}.
bind
(
this
))
})
it
(
"should allow decimals in max"
,
function
(
done
){
this
.
UserWithDec
.
create
({
value
:
3.5
}).
success
(
function
(){
this
.
UserWithDec
.
create
({
value
:
5.5
}).
success
(
function
(){
this
.
UserWithDec
.
max
(
'value'
).
success
(
function
(
max
){
expect
(
max
).
toEqual
(
5.5
)
done
()
})
}.
bind
(
this
))
}.
bind
(
this
))
})
it
(
'allows sql logging'
,
function
(
done
)
{
this
.
UserWithAge
.
max
(
'age'
).
on
(
'sql'
,
function
(
sql
)
{
expect
(
sql
).
toBeDefined
()
...
...
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