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 f15dcc21
authored
Nov 21, 2011
by
Sascha Depold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
moved count query to queryinterface
1 parent
e6bae76f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
8 deletions
lib/model-factory.js
lib/query-interface.js
lib/model-factory.js
View file @
f15dcc2
...
...
@@ -68,14 +68,7 @@ module.exports = (function() {
}
ModelFactory
.
prototype
.
count
=
function
(
options
)
{
var
self
=
this
var
emitter
=
new
Utils
.
CustomEventEmitter
(
function
()
{
query
.
call
(
self
,
self
.
QueryGenerator
.
countQuery
(
self
.
tableName
,
options
),
self
,
{
plain
:
true
}).
success
(
function
(
obj
)
{
emitter
.
emit
(
'success'
,
obj
[
'count(*)'
])
})
})
return
emitter
.
run
()
return
this
.
QueryInterface
.
count
(
this
,
this
.
tableName
,
options
)
}
ModelFactory
.
prototype
.
max
=
function
(
field
,
options
)
{
...
...
lib/query-interface.js
View file @
f15dcc2
...
...
@@ -58,6 +58,35 @@ module.exports = (function() {
return
query
.
call
(
this
,
this
.
QueryGenerator
.
selectQuery
(
tableName
,
options
),
factory
)
}
QueryInterface
.
prototype
.
count
=
function
(
factory
,
tableName
,
options
)
{
var
self
=
this
,
countOption
=
"count(*) as count"
options
=
options
||
{}
options
.
attributes
=
options
.
attributes
||
[]
options
.
attributes
.
push
(
'count(*) as count'
)
return
new
Utils
.
CustomEventEmitter
(
function
(
emitter
)
{
var
sql
=
self
.
QueryGenerator
.
selectQuery
(
tableName
,
options
).
replace
(
'`'
+
countOption
+
'`'
,
countOption
)
query
.
call
(
self
,
sql
,
factory
,
{
plain
:
true
}).
success
(
function
(
data
)
{
emitter
.
emit
(
'success'
,
data
.
count
)
}).
error
(
function
(
err
)
{
emitter
.
emit
(
'failure'
,
err
)
})
}).
run
()
var
self
=
this
var
emitter
=
new
Utils
.
CustomEventEmitter
(
function
()
{
query
.
call
(
self
,
self
.
QueryGenerator
.
countQuery
(
self
.
tableName
,
options
),
self
,
{
plain
:
true
}).
success
(
function
(
obj
)
{
emitter
.
emit
(
'success'
,
obj
[
'count(*)'
])
})
})
return
emitter
.
run
()
}
// private
var
query
=
function
()
{
...
...
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