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 7cf8e14b
authored
Jun 30, 2012
by
sdepold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use error event instead of failure
1 parent
74a0ef95
Hide whitespace changes
Inline
Side-by-side
Showing
21 changed files
with
73 additions
and
74 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/dao-factory.js
lib/dialects/mysql/connector-manager.js
lib/dialects/mysql/query.js
lib/dialects/postgres/query.js
lib/dialects/query.js
lib/dialects/sqlite/query.js
lib/emitters/custom-event-emitter.js
lib/emitters/null-emitter.js
lib/migrator.js
lib/query-chainer.js
lib/query-interface.js
lib/sequelize.js
spec-jasmine/config/factories.js
spec-jasmine/config/helpers.js
spec-jasmine/sqlite/dao-factory.spec.js
spec/config/factories.js
spec/config/helpers.js
lib/associations/has-many-double-linked.js
View file @
7cf8e14
...
...
@@ -20,7 +20,7 @@ module.exports = (function() {
where
[
self
.
__factory
.
connectorDAO
.
tableName
+
"."
+
foreignKey
]
=
{
join
:
self
.
__factory
.
target
.
tableName
+
".id"
}
self
.
__factory
.
target
.
findAllJoin
(
self
.
__factory
.
connectorDAO
.
tableName
,
{
where
:
where
})
.
on
(
'success'
,
function
(
objects
)
{
customEventEmitter
.
emit
(
'success'
,
objects
)
})
.
on
(
'
failure'
,
function
(
err
){
customEventEmitter
.
emit
(
'failure
'
,
err
)
})
.
on
(
'
error'
,
function
(
err
){
customEventEmitter
.
emit
(
'error
'
,
err
)
})
.
on
(
'sql'
,
function
(
sql
)
{
customEventEmitter
.
emit
(
'sql'
,
sql
)})
})
...
...
@@ -31,7 +31,7 @@ module.exports = (function() {
var
self
=
this
destroyObsoleteAssociations
.
call
(
this
,
oldAssociations
,
newAssociations
)
.
error
(
function
(
err
)
{
emitter
.
emit
(
'
failure
'
,
err
)
})
.
error
(
function
(
err
)
{
emitter
.
emit
(
'
error
'
,
err
)
})
.
on
(
'sql'
,
function
(
sql
)
{
emitter
.
emit
(
'sql'
,
sql
)
})
.
success
(
function
()
{
var
chainer
=
new
Utils
.
QueryChainer
...
...
@@ -50,7 +50,7 @@ module.exports = (function() {
chainer
.
run
()
.
success
(
function
()
{
emitter
.
emit
(
'success'
,
newAssociations
)
})
.
error
(
function
(
err
)
{
emitter
.
emit
(
'
failure
'
,
err
)
})
.
error
(
function
(
err
)
{
emitter
.
emit
(
'
error
'
,
err
)
})
.
on
(
'sql'
,
function
(
sql
)
{
emitter
.
emit
(
'sql'
,
sql
)
})
})
}
...
...
@@ -84,7 +84,7 @@ module.exports = (function() {
chainer
.
run
()
.
success
(
function
()
{
emitter
.
emit
(
'success'
,
null
)
})
.
error
(
function
(
err
)
{
emitter
.
emit
(
'
failure
'
,
err
)
})
.
error
(
function
(
err
)
{
emitter
.
emit
(
'
error
'
,
err
)
})
.
on
(
'sql'
,
function
(
sql
)
{
emitter
.
emit
(
'sql'
,
sql
)
})
}
})
...
...
lib/associations/has-many-single-linked.js
View file @
7cf8e14
...
...
@@ -31,7 +31,7 @@ module.exports = (function() {
chainer
.
run
()
.
success
(
function
()
{
emitter
.
emit
(
'success'
,
newAssociations
)
})
.
error
(
function
(
err
)
{
emitter
.
emit
(
'
failure
'
,
err
)
})
.
error
(
function
(
err
)
{
emitter
.
emit
(
'
error
'
,
err
)
})
}
return
HasManySingleLinked
...
...
lib/associations/has-many.js
View file @
7cf8e14
...
...
@@ -24,8 +24,8 @@ module.exports = (function() {
set
:
Utils
.
_
.
camelize
(
'set_'
+
as
),
add
:
Utils
.
_
.
camelize
(
Utils
.
singularize
(
'add_'
+
as
)),
remove
:
Utils
.
_
.
camelize
(
Utils
.
singularize
(
'remove_'
+
as
)),
hasSingle
:
Utils
.
_
.
camelize
(
Utils
.
singularize
(
'has_'
+
as
)),
hasAll
:
Utils
.
_
.
camelize
(
'has_'
+
as
)
hasSingle
:
Utils
.
_
.
camelize
(
Utils
.
singularize
(
'has_'
+
as
)),
hasAll
:
Utils
.
_
.
camelize
(
'has_'
+
as
)
}
}
...
...
@@ -73,44 +73,44 @@ module.exports = (function() {
var
Class
=
self
.
connectorDAO
?
HasManyMultiLinked
:
HasManySingleLinked
return
new
Class
(
self
,
this
).
injectGetter
()
}
obj
[
this
.
accessors
.
hasAll
]
=
function
(
objects
)
{
var
instance
=
this
;
obj
[
this
.
accessors
.
hasAll
]
=
function
(
objects
)
{
var
instance
=
this
;
var
customEventEmitter
=
new
Utils
.
CustomEventEmitter
(
function
()
{
instance
[
self
.
accessors
.
get
]()
.
error
(
function
(
err
){
customEventEmitter
.
emit
(
'failure
'
,
err
)})
.
success
(
function
(
associatedObjects
)
{
customEventEmitter
.
emit
(
'success'
,
Utils
.
_
.
all
(
objects
,
function
(
o
)
{
return
Utils
.
_
.
any
(
associatedObjects
,
function
(
associatedObject
)
{
return
Utils
.
_
.
all
(
associatedObject
.
identifiers
,
function
(
key
,
identifier
)
{
return
o
[
identifier
]
==
associatedObject
[
identifier
];
});
})
})
)
})
.
error
(
function
(
err
){
customEventEmitter
.
emit
(
'error
'
,
err
)})
.
success
(
function
(
associatedObjects
)
{
customEventEmitter
.
emit
(
'success'
,
Utils
.
_
.
all
(
objects
,
function
(
o
)
{
return
Utils
.
_
.
any
(
associatedObjects
,
function
(
associatedObject
)
{
return
Utils
.
_
.
all
(
associatedObject
.
identifiers
,
function
(
key
,
identifier
)
{
return
o
[
identifier
]
==
associatedObject
[
identifier
];
});
})
})
)
})
})
return
customEventEmitter
.
run
()
}
obj
[
this
.
accessors
.
hasSingle
]
=
function
(
o
)
{
var
instance
=
this
;
}
obj
[
this
.
accessors
.
hasSingle
]
=
function
(
o
)
{
var
instance
=
this
;
var
customEventEmitter
=
new
Utils
.
CustomEventEmitter
(
function
()
{
instance
[
self
.
accessors
.
get
]()
.
error
(
function
(
err
){
customEventEmitter
.
emit
(
'failure
'
,
err
)})
.
success
(
function
(
associatedObjects
)
{
customEventEmitter
.
emit
(
'success'
,
Utils
.
_
.
any
(
associatedObjects
,
function
(
associatedObject
)
{
return
Utils
.
_
.
all
(
associatedObject
.
identifiers
,
function
(
key
,
identifier
)
{
return
o
[
identifier
]
==
associatedObject
[
identifier
];
});
})
)
})
.
error
(
function
(
err
){
customEventEmitter
.
emit
(
'error
'
,
err
)})
.
success
(
function
(
associatedObjects
)
{
customEventEmitter
.
emit
(
'success'
,
Utils
.
_
.
any
(
associatedObjects
,
function
(
associatedObject
)
{
return
Utils
.
_
.
all
(
associatedObject
.
identifiers
,
function
(
key
,
identifier
)
{
return
o
[
identifier
]
==
associatedObject
[
identifier
];
});
})
)
})
})
return
customEventEmitter
.
run
()
}
}
return
this
}
...
...
@@ -134,14 +134,14 @@ module.exports = (function() {
var
instance
=
this
var
customEventEmitter
=
new
Utils
.
CustomEventEmitter
(
function
()
{
instance
[
self
.
accessors
.
get
]()
.
error
(
function
(
err
){
customEventEmitter
.
emit
(
'
failure
'
,
err
)})
.
error
(
function
(
err
){
customEventEmitter
.
emit
(
'
error
'
,
err
)})
.
success
(
function
(
currentAssociatedObjects
)
{
if
(
!
newAssociatedObject
.
equalsOneOf
(
currentAssociatedObjects
))
currentAssociatedObjects
.
push
(
newAssociatedObject
)
instance
[
self
.
accessors
.
set
](
currentAssociatedObjects
)
.
success
(
function
(
instances
)
{
customEventEmitter
.
emit
(
'success'
,
instances
)
})
.
error
(
function
(
err
)
{
customEventEmitter
.
emit
(
'
failure
'
,
err
)
})
.
error
(
function
(
err
)
{
customEventEmitter
.
emit
(
'
error
'
,
err
)
})
})
})
return
customEventEmitter
.
run
()
...
...
@@ -160,7 +160,7 @@ module.exports = (function() {
instance
[
self
.
accessors
.
set
](
newAssociations
)
.
success
(
function
()
{
customEventEmitter
.
emit
(
'success'
,
null
)
})
.
error
(
function
(
err
)
{
customEventEmitter
.
emit
(
'
failure
'
,
err
)
})
.
error
(
function
(
err
)
{
customEventEmitter
.
emit
(
'
error
'
,
err
)
})
})
})
return
customEventEmitter
.
run
()
...
...
lib/associations/has-one.js
View file @
7cf8e14
...
...
@@ -60,7 +60,7 @@ module.exports = (function() {
associatedObject
[
self
.
identifier
]
=
obj
.
id
associatedObject
.
save
()
.
success
(
function
()
{
customEventEmitter
.
emit
(
'success'
,
associatedObject
)
})
.
error
(
function
(
err
)
{
customEventEmitter
.
emit
(
'
failure
'
,
err
)
})
.
error
(
function
(
err
)
{
customEventEmitter
.
emit
(
'
error
'
,
err
)
})
})
})
return
customEventEmitter
.
run
()
...
...
@@ -70,4 +70,4 @@ module.exports = (function() {
}
return
HasOne
})()
\ No newline at end of file
})()
lib/dao-factory.js
View file @
7cf8e14
...
...
@@ -68,12 +68,12 @@ module.exports = (function() {
self
.
QueryInterface
.
createTable
(
self
.
tableName
,
self
.
attributes
,
options
)
.
success
(
function
()
{
emitter
.
emit
(
'success'
,
self
)
})
.
error
(
function
(
err
)
{
emitter
.
emit
(
'
failure
'
,
err
)
})
.
error
(
function
(
err
)
{
emitter
.
emit
(
'
error
'
,
err
)
})
.
on
(
'sql'
,
function
(
sql
)
{
emitter
.
emit
(
'sql'
,
sql
)
})
}
if
(
options
.
force
)
self
.
drop
().
success
(
doQuery
).
error
(
function
(
err
)
{
emitter
.
emit
(
'
failure
'
,
err
)
})
self
.
drop
().
success
(
doQuery
).
error
(
function
(
err
)
{
emitter
.
emit
(
'
error
'
,
err
)
})
else
doQuery
()
...
...
lib/dialects/mysql/connector-manager.js
View file @
7cf8e14
...
...
@@ -127,7 +127,7 @@ module.exports = (function() {
var
self
=
this
this
.
pool
.
acquire
(
function
(
err
,
client
)
{
if
(
err
)
{
queueItem
.
query
.
emit
(
'
failure
'
,
err
)
queueItem
.
query
.
emit
(
'
error
'
,
err
)
return
}
//we set the client here, asynchronously, when getting a pooled connection
...
...
lib/dialects/mysql/query.js
View file @
7cf8e14
...
...
@@ -90,7 +90,7 @@ module.exports = (function() {
var
onFailure
=
function
(
err
)
{
unbindClient
.
call
(
this
)
this
.
emit
(
'
failure
'
,
err
,
this
.
callee
)
this
.
emit
(
'
error
'
,
err
,
this
.
callee
)
}
return
Query
...
...
lib/dialects/postgres/query.js
View file @
7cf8e14
...
...
@@ -85,7 +85,7 @@ module.exports = (function() {
query
.
on
(
'error'
,
function
(
err
)
{
receivedError
=
true
self
.
emit
(
'
failure
'
,
err
,
self
.
callee
)
self
.
emit
(
'
error
'
,
err
,
self
.
callee
)
});
return
this
...
...
lib/dialects/query.js
View file @
7cf8e14
...
...
@@ -16,7 +16,7 @@ module.exports = (function() {
}
Query
.
prototype
.
failure
=
Query
.
prototype
.
fail
=
Query
.
prototype
.
error
=
function
(
fct
)
{
this
.
on
(
'
failure
'
,
fct
)
this
.
on
(
'
error
'
,
fct
)
return
this
}
...
...
lib/dialects/sqlite/query.js
View file @
7cf8e14
...
...
@@ -108,7 +108,7 @@ module.exports = (function() {
}
var
onFailure
=
function
(
err
)
{
this
.
emit
(
'
failure
'
,
err
,
this
.
callee
)
this
.
emit
(
'
error
'
,
err
,
this
.
callee
)
}
return
Query
...
...
lib/emitters/custom-event-emitter.js
View file @
7cf8e14
...
...
@@ -29,14 +29,14 @@ module.exports = (function() {
CustomEventEmitter
.
prototype
.
fail
=
CustomEventEmitter
.
prototype
.
error
=
function
(
fct
)
{
this
.
on
(
'
failure
'
,
fct
)
this
.
on
(
'
error
'
,
fct
)
return
this
}
CustomEventEmitter
.
prototype
.
done
=
CustomEventEmitter
.
prototype
.
complete
=
function
(
fct
)
{
this
.
on
(
'
failure
'
,
function
(
err
)
{
fct
(
err
,
null
)
})
this
.
on
(
'
error
'
,
function
(
err
)
{
fct
(
err
,
null
)
})
.
on
(
'success'
,
function
(
result
)
{
fct
(
null
,
result
)
})
return
this
}
...
...
lib/emitters/null-emitter.js
View file @
7cf8e14
...
...
@@ -11,7 +11,7 @@ module.exports = (function(){
NullEmitter
.
prototype
.
emitNull
=
function
()
{
this
.
emit
(
'success'
,
null
)
this
.
emit
(
'
failure
'
,
null
)
this
.
emit
(
'
error
'
,
null
)
}
return
NullEmitter
...
...
lib/migrator.js
View file @
7cf8e14
...
...
@@ -43,7 +43,7 @@ module.exports = (function() {
return
new
Utils
.
CustomEventEmitter
(
function
(
emitter
)
{
self
.
getUndoneMigrations
(
function
(
err
,
migrations
)
{
if
(
err
)
{
emitter
.
emit
(
'
failure
'
,
err
)
emitter
.
emit
(
'
error
'
,
err
)
}
else
{
var
chainer
=
new
Utils
.
QueryChainer
,
from
=
migrations
[
0
]
...
...
@@ -75,7 +75,7 @@ module.exports = (function() {
chainer
.
runSerially
({
skipOnError
:
true
})
.
success
(
function
()
{
emitter
.
emit
(
'success'
,
null
)
})
.
error
(
function
(
err
)
{
emitter
.
emit
(
'
failure
'
,
err
)
})
.
error
(
function
(
err
)
{
emitter
.
emit
(
'
error
'
,
err
)
})
}
})
}).
run
()
...
...
@@ -152,7 +152,7 @@ module.exports = (function() {
SequelizeMeta
.
sync
(
syncOptions
||
{})
.
success
(
function
()
{
emitter
.
emit
(
'success'
,
SequelizeMeta
)
})
.
error
(
function
(
err
)
{
emitter
.
emit
(
'
failure
'
,
err
)
})
.
error
(
function
(
err
)
{
emitter
.
emit
(
'
error
'
,
err
)
})
}
else
{
emitter
.
emit
(
'success'
,
SequelizeMeta
)
}
...
...
@@ -168,7 +168,7 @@ module.exports = (function() {
self
.
findOrCreateSequelizeMetaDAO
().
success
(
function
(
SequelizeMeta
)
{
SequelizeMeta
.
find
({
order
:
'id DESC'
}).
success
(
function
(
meta
)
{
emitter
.
emit
(
'success'
,
meta
?
meta
:
null
)
}).
error
(
function
(
err
)
{
emitter
.
emit
(
'
failure
'
,
err
)
})
}).
error
(
function
(
err
)
{
emitter
.
emit
(
'
error
'
,
err
)
})
}).
error
(
function
(
err
)
{
emitter
.
emit
(
err
)
})
}).
run
()
}
...
...
@@ -182,7 +182,7 @@ module.exports = (function() {
emitter
.
emit
(
'success'
,
meta
?
meta
.
to
:
null
)
})
.
error
(
function
(
err
)
{
emitter
.
emit
(
'
failure
'
,
err
)
emitter
.
emit
(
'
error
'
,
err
)
})
}).
run
()
}
...
...
lib/query-chainer.js
View file @
7cf8e14
...
...
@@ -116,7 +116,7 @@ module.exports = (function() {
this
.
finished
=
(
this
.
finishedEmits
==
this
.
serials
.
length
)
if
(
this
.
finished
&&
this
.
wasRunning
)
{
var
status
=
(
this
.
fails
.
length
==
0
?
'success'
:
'
failure
'
)
var
status
=
(
this
.
fails
.
length
==
0
?
'success'
:
'
error
'
)
,
result
=
(
this
.
fails
.
length
==
0
?
result
:
this
.
fails
)
this
.
eventEmitter
.
emit
(
status
,
result
)
...
...
lib/query-interface.js
View file @
7cf8e14
...
...
@@ -48,11 +48,11 @@ module.exports = (function() {
})
.
error
(
function
(
err
)
{
self
.
emit
(
'dropAllTables'
,
err
)
emitter
.
emit
(
'
failure
'
,
err
)
emitter
.
emit
(
'
error
'
,
err
)
})
}).
error
(
function
(
err
)
{
self
.
emit
(
'dropAllTables'
,
err
)
emitter
.
emit
(
'
failure
'
,
err
)
emitter
.
emit
(
'
error
'
,
err
)
})
}).
run
()
}
...
...
@@ -72,7 +72,7 @@ module.exports = (function() {
emitter
.
emit
(
'success'
,
Utils
.
_
.
flatten
(
tableNames
))
}).
error
(
function
(
err
)
{
self
.
emit
(
'showAllTables'
,
err
)
emitter
.
emit
(
'
failure
'
,
err
)
emitter
.
emit
(
'
error
'
,
err
)
})
}).
run
()
}
...
...
@@ -90,7 +90,7 @@ module.exports = (function() {
self
.
sequelize
.
query
(
sql
,
null
,
{
raw
:
true
}).
success
(
function
(
data
)
{
emitter
.
emit
(
'success'
,
data
)
}).
error
(
function
(
err
)
{
emitter
.
emit
(
'
failure
'
,
err
)
emitter
.
emit
(
'
error
'
,
err
)
})
}).
run
()
}
...
...
@@ -153,11 +153,11 @@ module.exports = (function() {
emitter
.
emit
(
'success'
,
null
)
}).
error
(
function
(
err
)
{
self
.
emit
(
'renameColumn'
,
err
)
emitter
.
emit
(
'
failure
'
,
err
)
emitter
.
emit
(
'
error
'
,
err
)
})
}).
error
(
function
(
err
)
{
self
.
emit
(
'renameColumn'
,
err
)
emitter
.
emit
(
'
failure
'
,
err
)
emitter
.
emit
(
'
error
'
,
err
)
})
}).
run
()
}
...
...
@@ -217,7 +217,7 @@ module.exports = (function() {
})
.
error
(
function
(
err
)
{
self
.
emit
(
'rawSelect'
,
err
)
emitter
.
emit
(
'
failure
'
,
err
)
emitter
.
emit
(
'
error
'
,
err
)
})
qry
.
on
(
'sql'
,
function
(
sql
)
{
emitter
.
emit
(
'sql'
,
sql
)
...
...
@@ -253,7 +253,7 @@ module.exports = (function() {
}).
error
(
function
(
err
)
{
options
.
error
&&
options
.
error
(
err
)
self
.
emit
(
methodName
,
err
)
emitter
.
emit
(
'
failure
'
,
err
)
emitter
.
emit
(
'
error
'
,
err
)
})
query
.
on
(
'sql'
,
function
(
sql
)
{
emitter
.
emit
(
'sql'
,
sql
)
...
...
lib/sequelize.js
View file @
7cf8e14
...
...
@@ -115,7 +115,7 @@ module.exports = (function() {
chainer
.
run
()
.
success
(
function
()
{
emitter
.
emit
(
'success'
,
null
)
})
.
error
(
function
(
err
)
{
emitter
.
emit
(
'
failure
'
,
err
)
})
.
error
(
function
(
err
)
{
emitter
.
emit
(
'
error
'
,
err
)
})
}).
run
()
}
...
...
@@ -130,7 +130,7 @@ module.exports = (function() {
chainer
.
run
()
.
success
(
function
()
{
emitter
.
emit
(
'success'
,
null
)
})
.
error
(
function
(
err
)
{
emitter
.
emit
(
'
failure
'
,
err
)
})
.
error
(
function
(
err
)
{
emitter
.
emit
(
'
error
'
,
err
)
})
}).
run
()
}
...
...
spec-jasmine/config/factories.js
View file @
7cf8e14
...
...
@@ -16,7 +16,7 @@ Factories.prototype.DAO = function(daoName, options, callback, count) {
DAO
.
create
(
options
).
on
(
'success'
,
function
(
dao
)
{
daos
.
push
(
dao
)
cb
&&
cb
()
}).
on
(
'
failure
'
,
function
(
err
)
{
}).
on
(
'
error
'
,
function
(
err
)
{
console
.
log
(
err
)
done
()
})
...
...
spec-jasmine/config/helpers.js
View file @
7cf8e14
...
...
@@ -21,7 +21,7 @@ Helpers.prototype.drop = function() {
self
.
sequelize
.
drop
()
.
on
(
'success'
,
done
)
.
on
(
'
failure
'
,
function
(
err
)
{
console
.
log
(
err
)
})
.
on
(
'
error
'
,
function
(
err
)
{
console
.
log
(
err
)
})
})
}
...
...
spec-jasmine/sqlite/dao-factory.spec.js
View file @
7cf8e14
...
...
@@ -161,7 +161,7 @@ describe('DAOFactory', function() {
User
.
all
().
on
(
'success'
,
function
(
users
)
{
done
()
expect
(
users
.
length
).
toEqual
(
2
)
}).
on
(
'
failure
'
,
function
(
err
)
{
console
.
log
(
err
)
})
}).
on
(
'
error
'
,
function
(
err
)
{
console
.
log
(
err
)
})
})
})
})
...
...
spec/config/factories.js
View file @
7cf8e14
...
...
@@ -16,7 +16,7 @@ Factories.prototype.DAO = function(daoName, options, callback, count) {
DAO
.
create
(
options
).
on
(
'success'
,
function
(
dao
)
{
daos
.
push
(
dao
)
cb
&&
cb
()
}).
on
(
'
failure
'
,
function
(
err
)
{
}).
on
(
'
error
'
,
function
(
err
)
{
console
.
log
(
err
)
done
()
})
...
...
spec/config/helpers.js
View file @
7cf8e14
...
...
@@ -21,7 +21,7 @@ Helpers.prototype.drop = function() {
self
.
sequelize
.
drop
()
.
on
(
'success'
,
done
)
.
on
(
'
failure
'
,
function
(
err
)
{
console
.
log
(
err
)
})
.
on
(
'
error
'
,
function
(
err
)
{
console
.
log
(
err
)
})
})
}
...
...
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