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 d590fe20
authored
Nov 18, 2011
by
Sascha Depold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use the stored sql instead of passing it to the function
1 parent
b9820b7d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
6 deletions
lib/query.js
lib/query.js
View file @
d590fe2
...
...
@@ -14,9 +14,10 @@ module.exports = (function() {
}
Utils
.
addEventEmitter
(
Query
)
Query
.
prototype
.
run
=
function
(
query
)
{
Query
.
prototype
.
run
=
function
(
sql
)
{
var
self
=
this
this
.
sql
=
query
this
.
sql
=
sql
bindClient
.
call
(
this
)
...
...
@@ -24,7 +25,7 @@ module.exports = (function() {
console
.
log
(
'Executing: '
+
this
.
sql
)
this
.
client
.
query
(
this
.
sql
,
function
(
err
,
results
,
fields
)
{
err
?
onFailure
.
call
(
self
,
err
)
:
onSuccess
.
call
(
self
,
self
.
sql
,
results
,
fields
)
err
?
onFailure
.
call
(
self
,
err
)
:
onSuccess
.
call
(
self
,
results
,
fields
)
}).
setMaxListeners
(
100
)
return
this
...
...
@@ -50,17 +51,17 @@ module.exports = (function() {
this
.
client
.
removeListener
(
'error'
,
this
.
bindClientFunction
)
}
var
onSuccess
=
function
(
query
,
results
,
fields
)
{
var
onSuccess
=
function
(
results
,
fields
)
{
var
result
=
this
.
callee
,
self
=
this
// add the inserted row id to the instance
if
(
this
.
callee
&&
(
query
.
indexOf
(
'INSERT INTO'
)
==
0
)
&&
(
results
.
hasOwnProperty
(
'insertId'
)))
if
(
this
.
callee
&&
(
this
.
sql
.
indexOf
(
'INSERT INTO'
)
==
0
)
&&
(
results
.
hasOwnProperty
(
'insertId'
)))
this
.
callee
[
this
.
callee
.
__definition
.
autoIncrementField
]
=
results
.
insertId
// transform results into real model instances
// return the first real model instance if options.plain is set (e.g. Model.find)
if
(
query
.
indexOf
(
'SELECT'
)
==
0
)
{
if
(
this
.
sql
.
indexOf
(
'SELECT'
)
==
0
)
{
result
=
results
.
map
(
function
(
result
)
{
return
self
.
callee
.
build
(
result
,
{
isNewRecord
:
false
})
})
if
(
this
.
options
.
plain
)
...
...
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