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 b933c8bd
authored
Oct 28, 2011
by
Laurent Zuijdwijk
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added min and max functions to the model
1 parent
c740ae1a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
1 deletions
lib/sequelize/model-definition.js
lib/sequelize/query-generator.js
lib/sequelize/model-definition.js
View file @
b933c8b
...
@@ -107,6 +107,26 @@ ModelDefinition.prototype.count = function(options) {
...
@@ -107,6 +107,26 @@ ModelDefinition.prototype.count = function(options) {
return
emitter
.
run
()
return
emitter
.
run
()
}
}
ModelDefinition
.
prototype
.
max
=
function
(
field
,
options
)
{
var
self
=
this
var
emitter
=
new
Utils
.
CustomEventEmitter
(
function
()
{
self
.
query
(
QueryGenerator
.
maxQuery
(
self
.
tableName
,
field
,
options
),
self
,
{
plain
:
true
}).
on
(
'success'
,
function
(
obj
)
{
emitter
.
emit
(
'success'
,
obj
[
'max'
])
})
})
return
emitter
.
run
()
}
ModelDefinition
.
prototype
.
min
=
function
(
field
,
options
)
{
var
self
=
this
var
emitter
=
new
Utils
.
CustomEventEmitter
(
function
()
{
self
.
query
(
QueryGenerator
.
minQuery
(
self
.
tableName
,
field
,
options
),
self
,
{
plain
:
true
}).
on
(
'success'
,
function
(
obj
)
{
emitter
.
emit
(
'success'
,
obj
[
'min'
])
})
})
return
emitter
.
run
()
}
ModelDefinition
.
prototype
.
findAll
=
function
(
options
)
{
ModelDefinition
.
prototype
.
findAll
=
function
(
options
)
{
return
this
.
query
(
QueryGenerator
.
selectQuery
(
this
.
tableName
,
options
))
return
this
.
query
(
QueryGenerator
.
selectQuery
(
this
.
tableName
,
options
))
}
}
...
...
lib/sequelize/query-generator.js
View file @
b933c8b
...
@@ -78,7 +78,12 @@ var QueryGenerator = module.exports = {
...
@@ -78,7 +78,12 @@ var QueryGenerator = module.exports = {
countQuery
:
function
(
tableName
,
options
)
{
countQuery
:
function
(
tableName
,
options
)
{
return
QueryGenerator
.
selectQuery
(
tableName
,
options
).
replace
(
"*"
,
"count(*)"
)
return
QueryGenerator
.
selectQuery
(
tableName
,
options
).
replace
(
"*"
,
"count(*)"
)
},
},
maxQuery
:
function
(
tableName
,
field
,
options
)
{
return
QueryGenerator
.
selectQuery
(
tableName
,
options
).
replace
(
"*"
,
"max("
+
field
+
") as max"
)
},
minQuery
:
function
(
tableName
,
field
,
options
)
{
return
QueryGenerator
.
selectQuery
(
tableName
,
options
).
replace
(
"*"
,
"min("
+
field
+
") as min"
)
},
/*
/*
Returns an insert into command. Parameters: table name + hash of attribute-value-pairs.
Returns an insert into command. Parameters: table name + hash of attribute-value-pairs.
*/
*/
...
...
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