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 a9ea2c57
authored
Nov 16, 2011
by
Sascha Depold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use new success binder
1 parent
b445c871
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
24 additions
and
24 deletions
lib/associations/has-many-double-linked.js
lib/associations/has-many-single-linked.js
lib/associations/has-many.js
lib/associations/has-one.js
lib/connectors/mysql/connector-manager.js
lib/emitters/custom-event-emitter.js
lib/model-factory.js
lib/model.js
lib/query-chainer.js
lib/query.js
lib/sequelize.js
lib/associations/has-many-double-linked.js
View file @
a9ea2c5
...
...
@@ -16,14 +16,14 @@ module.exports = (function() {
var
primaryKeys
=
Utils
.
_
.
keys
(
self
.
__definition
.
connectorModel
.
rawAttributes
)
,
foreignKey
=
primaryKeys
.
filter
(
function
(
pk
)
{
return
pk
!=
self
.
__definition
.
identifier
})[
0
]
self
.
__definition
.
connectorModel
.
findAll
({
where
:
where
}).
on
(
'success'
,
function
(
associatedObjects
)
{
self
.
__definition
.
connectorModel
.
findAll
({
where
:
where
}).
success
(
function
(
associatedObjects
)
{
var
ids
=
associatedObjects
.
map
(
function
(
obj
)
{
return
obj
[
foreignKey
]
})
if
(
ids
.
length
==
0
)
{
customEventEmitter
.
emit
(
'success'
,
[])
}
else
{
self
.
__definition
.
target
.
findAll
({
where
:
'id in ('
+
ids
.
join
(
", "
)
+
')'
})
.
on
(
'success'
,
function
(
objects
)
{
customEventEmitter
.
emit
(
'success'
,
objects
)
})
.
success
(
function
(
objects
)
{
customEventEmitter
.
emit
(
'success'
,
objects
)
})
.
on
(
'failure'
,
function
(
err
){
customEventEmitter
.
emit
(
'failure'
,
err
)
})
}
})
...
...
@@ -37,7 +37,7 @@ module.exports = (function() {
destroyObsoleteAssociations
.
call
(
this
,
oldAssociations
,
newAssociations
)
.
on
(
'failure'
,
function
(
err
)
{
emitter
.
emit
(
'failure'
,
err
)
})
.
on
(
'success'
,
function
()
{
.
success
(
function
()
{
var
chainer
=
new
Utils
.
QueryChainer
,
association
=
self
.
__definition
.
target
.
associations
[
self
.
__definition
.
associationAccessor
]
,
foreignIdentifier
=
association
.
isSelfAssociation
?
association
.
foreignIdentifier
:
association
.
identifier
...
...
@@ -53,7 +53,7 @@ module.exports = (function() {
chainer
.
run
()
.
on
(
'success'
,
function
()
{
emitter
.
emit
(
'success'
,
newAssociations
)
})
.
success
(
function
()
{
emitter
.
emit
(
'success'
,
newAssociations
)
})
.
on
(
'failure'
,
function
(
err
)
{
emitter
.
emit
(
'failure'
,
err
)
})
})
}
...
...
@@ -79,14 +79,14 @@ module.exports = (function() {
where
[
self
.
__definition
.
identifier
]
=
self
.
instance
.
id
where
[
foreignKey
]
=
associatedObject
.
id
self
.
__definition
.
connectorModel
.
find
({
where
:
where
}).
on
(
'success'
,
function
(
connector
)
{
self
.
__definition
.
connectorModel
.
find
({
where
:
where
}).
success
(
function
(
connector
)
{
chainer
.
add
(
connector
.
destroy
())
if
(
chainer
.
emitters
.
length
==
obsoleteAssociations
.
length
)
{
// found all obsolete connectors and will delete them now
chainer
.
run
()
.
on
(
'success'
,
function
()
{
emitter
.
emit
(
'success'
,
null
)
})
.
success
(
function
()
{
emitter
.
emit
(
'success'
,
null
)
})
.
on
(
'failure'
,
function
(
err
)
{
emitter
.
emit
(
'failure'
,
err
)
})
}
})
...
...
lib/associations/has-many-single-linked.js
View file @
a9ea2c5
...
...
@@ -30,7 +30,7 @@ module.exports = (function() {
})
chainer
.
run
()
.
on
(
'success'
,
function
()
{
emitter
.
emit
(
'success'
,
newAssociations
)
})
.
success
(
function
()
{
emitter
.
emit
(
'success'
,
newAssociations
)
})
.
on
(
'failure'
,
function
(
err
)
{
emitter
.
emit
(
'failure'
,
err
)
})
}
...
...
lib/associations/has-many.js
View file @
a9ea2c5
...
...
@@ -80,7 +80,7 @@ module.exports = (function() {
// define the returned customEventEmitter, which will emit the success event once everything is done
var
customEventEmitter
=
new
Utils
.
CustomEventEmitter
(
function
()
{
instance
[
self
.
accessors
.
get
]().
on
(
'success'
,
function
(
oldAssociatedObjects
)
{
instance
[
self
.
accessors
.
get
]().
success
(
function
(
oldAssociatedObjects
)
{
var
Class
=
self
.
connectorModel
?
HasManyMultiLinked
:
HasManySingleLinked
new
Class
(
self
,
instance
).
injectSetter
(
customEventEmitter
,
oldAssociatedObjects
,
newAssociatedObjects
)
})
...
...
@@ -93,12 +93,12 @@ module.exports = (function() {
var
customEventEmitter
=
new
Utils
.
CustomEventEmitter
(
function
()
{
instance
[
self
.
accessors
.
get
]()
.
on
(
'failure'
,
function
(
err
){
customEventEmitter
.
emit
(
'failure'
,
err
)})
.
on
(
'success'
,
function
(
currentAssociatedObjects
)
{
.
success
(
function
(
currentAssociatedObjects
)
{
if
(
!
newAssociatedObject
.
equalsOneOf
(
currentAssociatedObjects
))
currentAssociatedObjects
.
push
(
newAssociatedObject
)
instance
[
self
.
accessors
.
set
](
currentAssociatedObjects
)
.
on
(
'success'
,
function
(
instances
)
{
customEventEmitter
.
emit
(
'success'
,
instances
)
})
.
success
(
function
(
instances
)
{
customEventEmitter
.
emit
(
'success'
,
instances
)
})
.
on
(
'failure'
,
function
(
err
)
{
customEventEmitter
.
emit
(
'failure'
,
err
)
})
})
})
...
...
@@ -108,7 +108,7 @@ module.exports = (function() {
obj
[
this
.
accessors
.
remove
]
=
function
(
oldAssociatedObject
)
{
var
instance
=
this
var
customEventEmitter
=
new
Utils
.
CustomEventEmitter
(
function
()
{
instance
[
self
.
accessors
.
get
]().
on
(
'success'
,
function
(
currentAssociatedObjects
)
{
instance
[
self
.
accessors
.
get
]().
success
(
function
(
currentAssociatedObjects
)
{
var
newAssociations
=
[]
currentAssociatedObjects
.
forEach
(
function
(
association
)
{
...
...
@@ -117,7 +117,7 @@ module.exports = (function() {
})
instance
[
self
.
accessors
.
set
](
newAssociations
)
.
on
(
'success'
,
function
()
{
customEventEmitter
.
emit
(
'success'
,
null
)
})
.
success
(
function
()
{
customEventEmitter
.
emit
(
'success'
,
null
)
})
.
on
(
'failure'
,
function
(
err
)
{
customEventEmitter
.
emit
(
'failure'
,
err
)
})
})
})
...
...
lib/associations/has-one.js
View file @
a9ea2c5
...
...
@@ -51,7 +51,7 @@ module.exports = (function() {
obj
[
this
.
accessors
.
set
]
=
function
(
associatedObject
)
{
var
customEventEmitter
=
new
Utils
.
CustomEventEmitter
(
function
()
{
obj
[
self
.
accessors
.
get
]().
on
(
'success'
,
function
(
oldObj
)
{
obj
[
self
.
accessors
.
get
]().
success
(
function
(
oldObj
)
{
if
(
oldObj
)
{
oldObj
[
self
.
identifier
]
=
null
oldObj
.
save
()
...
...
@@ -59,7 +59,7 @@ module.exports = (function() {
associatedObject
[
self
.
identifier
]
=
obj
.
id
associatedObject
.
save
()
.
on
(
'success'
,
function
()
{
customEventEmitter
.
emit
(
'success'
,
associatedObject
)
})
.
success
(
function
()
{
customEventEmitter
.
emit
(
'success'
,
associatedObject
)
})
.
on
(
'failure'
,
function
(
err
)
{
customEventEmitter
.
emit
(
'failure'
,
err
)
})
})
})
...
...
lib/connectors/mysql/connector-manager.js
View file @
a9ea2c5
...
...
@@ -84,7 +84,7 @@ module.exports = (function() {
var
self
=
this
queueItem
.
query
.
on
(
'success'
,
function
(){
afterQuery
.
call
(
self
,
queueItem
)
})
.
success
(
function
(){
afterQuery
.
call
(
self
,
queueItem
)
})
.
on
(
'failure'
,
function
(){
afterQuery
.
call
(
self
,
queueItem
)
})
queueItem
.
query
.
run
(
queueItem
.
sql
)
...
...
lib/emitters/custom-event-emitter.js
View file @
a9ea2c5
...
...
@@ -19,7 +19,7 @@ module.exports = (function() {
}
CustomEventEmitter
.
prototype
.
success
=
CustomEventEmitter
.
prototype
.
ok
=
function
(
fct
)
{
this
.
success
(
fct
)
this
.
on
(
'success'
,
fct
)
return
this
}
...
...
lib/model-factory.js
View file @
a9ea2c5
...
...
@@ -62,7 +62,7 @@ module.exports = (function() {
var
self
=
this
var
emitter
=
new
Utils
.
CustomEventEmitter
(
function
()
{
query
.
call
(
self
,
self
.
QueryGenerator
.
countQuery
(
self
.
tableName
,
options
),
self
,
{
plain
:
true
}).
on
(
'success'
,
function
(
obj
)
{
query
.
call
(
self
,
self
.
QueryGenerator
.
countQuery
(
self
.
tableName
,
options
),
self
,
{
plain
:
true
}).
success
(
function
(
obj
)
{
emitter
.
emit
(
'success'
,
obj
[
'count(*)'
])
})
})
...
...
@@ -73,7 +73,7 @@ module.exports = (function() {
var
self
=
this
var
emitter
=
new
Utils
.
CustomEventEmitter
(
function
()
{
query
.
call
(
self
,
self
.
QueryGenerator
.
maxQuery
(
self
.
tableName
,
field
,
options
),
self
,
{
plain
:
true
}).
on
(
'success'
,
function
(
obj
)
{
query
.
call
(
self
,
self
.
QueryGenerator
.
maxQuery
(
self
.
tableName
,
field
,
options
),
self
,
{
plain
:
true
}).
success
(
function
(
obj
)
{
emitter
.
emit
(
'success'
,
obj
[
'max'
])
})
})
...
...
@@ -83,7 +83,7 @@ module.exports = (function() {
var
self
=
this
var
emitter
=
new
Utils
.
CustomEventEmitter
(
function
()
{
query
.
call
(
self
,
self
.
QueryGenerator
.
minQuery
(
self
.
tableName
,
field
,
options
),
self
,
{
plain
:
true
}).
on
(
'success'
,
function
(
obj
)
{
query
.
call
(
self
,
self
.
QueryGenerator
.
minQuery
(
self
.
tableName
,
field
,
options
),
self
,
{
plain
:
true
}).
success
(
function
(
obj
)
{
emitter
.
emit
(
'success'
,
obj
[
'min'
])
})
})
...
...
lib/model.js
View file @
a9ea2c5
...
...
@@ -35,7 +35,7 @@ module.exports = (function() {
var
self
=
this
var
eventEmitter
=
new
Utils
.
CustomEventEmitter
(
function
()
{
query
.
call
(
self
,
self
.
QueryGenerator
.
insertQuery
(
self
.
__definition
.
tableName
,
self
.
values
))
.
on
(
'success'
,
function
(
obj
)
{
.
success
(
function
(
obj
)
{
obj
.
isNewRecord
=
false
eventEmitter
.
emit
(
'success'
,
obj
)
})
...
...
lib/query-chainer.js
View file @
a9ea2c5
...
...
@@ -36,7 +36,7 @@ module.exports = (function() {
var
observeEmitter
=
function
(
emitter
)
{
var
self
=
this
emitter
.
on
(
'success'
,
function
(){
.
success
(
function
(){
self
.
finishedEmits
++
finish
.
call
(
self
)
})
...
...
lib/query.js
View file @
a9ea2c5
...
...
@@ -28,7 +28,7 @@ module.exports = (function() {
}
Query
.
prototype
.
success
=
Query
.
prototype
.
ok
=
function
(
fct
)
{
this
.
success
(
fct
)
this
.
on
(
'success'
,
fct
)
return
this
}
...
...
lib/sequelize.js
View file @
a9ea2c5
...
...
@@ -70,7 +70,7 @@ module.exports = (function() {
chainer
.
run
()
.
on
(
'success'
,
function
()
{
eventEmitter
.
emit
(
'success'
,
null
)
})
.
success
(
function
()
{
eventEmitter
.
emit
(
'success'
,
null
)
})
.
on
(
'failure'
,
function
(
err
)
{
eventEmitter
.
emit
(
'failure'
,
err
)
})
})
return
eventEmitter
.
run
()
...
...
@@ -86,7 +86,7 @@ module.exports = (function() {
chainer
.
run
()
.
on
(
'success'
,
function
()
{
emitter
.
emit
(
'success'
,
null
)
})
.
success
(
function
()
{
emitter
.
emit
(
'success'
,
null
)
})
.
on
(
'failure'
,
function
(
err
)
{
emitter
.
emit
(
'failure'
,
err
)
})
}).
run
()
}
...
...
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