不要怂,就是干,撸起袖子干!

Commit 7cf8e14b by sdepold

use error event instead of failure

1 parent 74a0ef95
...@@ -20,7 +20,7 @@ module.exports = (function() { ...@@ -20,7 +20,7 @@ module.exports = (function() {
where[self.__factory.connectorDAO.tableName+"."+foreignKey] = {join: self.__factory.target.tableName+".id"} where[self.__factory.connectorDAO.tableName+"."+foreignKey] = {join: self.__factory.target.tableName+".id"}
self.__factory.target.findAllJoin(self.__factory.connectorDAO.tableName, {where: where}) self.__factory.target.findAllJoin(self.__factory.connectorDAO.tableName, {where: where})
.on('success', function(objects) { customEventEmitter.emit('success', objects) }) .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)}) .on('sql', function(sql) { customEventEmitter.emit('sql', sql)})
}) })
...@@ -31,7 +31,7 @@ module.exports = (function() { ...@@ -31,7 +31,7 @@ module.exports = (function() {
var self = this var self = this
destroyObsoleteAssociations.call(this, oldAssociations, newAssociations) 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) }) .on('sql', function(sql) { emitter.emit('sql', sql) })
.success(function() { .success(function() {
var chainer = new Utils.QueryChainer var chainer = new Utils.QueryChainer
...@@ -50,7 +50,7 @@ module.exports = (function() { ...@@ -50,7 +50,7 @@ module.exports = (function() {
chainer chainer
.run() .run()
.success(function() { emitter.emit('success', newAssociations) }) .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) }) .on('sql', function(sql) { emitter.emit('sql', sql) })
}) })
} }
...@@ -84,7 +84,7 @@ module.exports = (function() { ...@@ -84,7 +84,7 @@ module.exports = (function() {
chainer chainer
.run() .run()
.success(function() { emitter.emit('success', null) }) .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) }) .on('sql', function(sql) { emitter.emit('sql', sql) })
} }
}) })
......
...@@ -31,7 +31,7 @@ module.exports = (function() { ...@@ -31,7 +31,7 @@ module.exports = (function() {
chainer chainer
.run() .run()
.success(function() { emitter.emit('success', newAssociations) }) .success(function() { emitter.emit('success', newAssociations) })
.error(function(err) { emitter.emit('failure', err) }) .error(function(err) { emitter.emit('error', err) })
} }
return HasManySingleLinked return HasManySingleLinked
......
...@@ -24,8 +24,8 @@ module.exports = (function() { ...@@ -24,8 +24,8 @@ module.exports = (function() {
set: Utils._.camelize('set_' + as), set: Utils._.camelize('set_' + as),
add: Utils._.camelize(Utils.singularize('add_' + as)), add: Utils._.camelize(Utils.singularize('add_' + as)),
remove: Utils._.camelize(Utils.singularize('remove_' + as)), remove: Utils._.camelize(Utils.singularize('remove_' + as)),
hasSingle: Utils._.camelize(Utils.singularize('has_' + as)), hasSingle: Utils._.camelize(Utils.singularize('has_' + as)),
hasAll: Utils._.camelize('has_' + as) hasAll: Utils._.camelize('has_' + as)
} }
} }
...@@ -73,44 +73,44 @@ module.exports = (function() { ...@@ -73,44 +73,44 @@ module.exports = (function() {
var Class = self.connectorDAO ? HasManyMultiLinked : HasManySingleLinked var Class = self.connectorDAO ? HasManyMultiLinked : HasManySingleLinked
return new Class(self, this).injectGetter() return new Class(self, this).injectGetter()
} }
obj[this.accessors.hasAll] = function(objects) { obj[this.accessors.hasAll] = function(objects) {
var instance = this; var instance = this;
var customEventEmitter = new Utils.CustomEventEmitter(function() { var customEventEmitter = new Utils.CustomEventEmitter(function() {
instance[self.accessors.get]() instance[self.accessors.get]()
.error(function(err){ customEventEmitter.emit('failure', err)}) .error(function(err){ customEventEmitter.emit('error', err)})
.success(function(associatedObjects) { .success(function(associatedObjects) {
customEventEmitter.emit('success', customEventEmitter.emit('success',
Utils._.all(objects, function(o) { Utils._.all(objects, function(o) {
return Utils._.any(associatedObjects, function(associatedObject) { return Utils._.any(associatedObjects, function(associatedObject) {
return Utils._.all(associatedObject.identifiers, function(key, identifier) { return Utils._.all(associatedObject.identifiers, function(key, identifier) {
return o[identifier] == associatedObject[identifier]; return o[identifier] == associatedObject[identifier];
}); });
}) })
}) })
) )
}) })
}) })
return customEventEmitter.run() return customEventEmitter.run()
} }
obj[this.accessors.hasSingle] = function(o) { obj[this.accessors.hasSingle] = function(o) {
var instance = this; var instance = this;
var customEventEmitter = new Utils.CustomEventEmitter(function() { var customEventEmitter = new Utils.CustomEventEmitter(function() {
instance[self.accessors.get]() instance[self.accessors.get]()
.error(function(err){ customEventEmitter.emit('failure', err)}) .error(function(err){ customEventEmitter.emit('error', err)})
.success(function(associatedObjects) { .success(function(associatedObjects) {
customEventEmitter.emit('success', customEventEmitter.emit('success',
Utils._.any(associatedObjects, function(associatedObject) { Utils._.any(associatedObjects, function(associatedObject) {
return Utils._.all(associatedObject.identifiers, function(key, identifier) { return Utils._.all(associatedObject.identifiers, function(key, identifier) {
return o[identifier] == associatedObject[identifier]; return o[identifier] == associatedObject[identifier];
}); });
}) })
) )
}) })
}) })
return customEventEmitter.run() return customEventEmitter.run()
} }
return this return this
} }
...@@ -134,14 +134,14 @@ module.exports = (function() { ...@@ -134,14 +134,14 @@ module.exports = (function() {
var instance = this var instance = this
var customEventEmitter = new Utils.CustomEventEmitter(function() { var customEventEmitter = new Utils.CustomEventEmitter(function() {
instance[self.accessors.get]() instance[self.accessors.get]()
.error(function(err){ customEventEmitter.emit('failure', err)}) .error(function(err){ customEventEmitter.emit('error', err)})
.success(function(currentAssociatedObjects) { .success(function(currentAssociatedObjects) {
if(!newAssociatedObject.equalsOneOf(currentAssociatedObjects)) if(!newAssociatedObject.equalsOneOf(currentAssociatedObjects))
currentAssociatedObjects.push(newAssociatedObject) currentAssociatedObjects.push(newAssociatedObject)
instance[self.accessors.set](currentAssociatedObjects) instance[self.accessors.set](currentAssociatedObjects)
.success(function(instances) { customEventEmitter.emit('success', instances) }) .success(function(instances) { customEventEmitter.emit('success', instances) })
.error(function(err) { customEventEmitter.emit('failure', err) }) .error(function(err) { customEventEmitter.emit('error', err) })
}) })
}) })
return customEventEmitter.run() return customEventEmitter.run()
...@@ -160,7 +160,7 @@ module.exports = (function() { ...@@ -160,7 +160,7 @@ module.exports = (function() {
instance[self.accessors.set](newAssociations) instance[self.accessors.set](newAssociations)
.success(function() { customEventEmitter.emit('success', null) }) .success(function() { customEventEmitter.emit('success', null) })
.error(function(err) { customEventEmitter.emit('failure', err) }) .error(function(err) { customEventEmitter.emit('error', err) })
}) })
}) })
return customEventEmitter.run() return customEventEmitter.run()
......
...@@ -60,7 +60,7 @@ module.exports = (function() { ...@@ -60,7 +60,7 @@ module.exports = (function() {
associatedObject[self.identifier] = obj.id associatedObject[self.identifier] = obj.id
associatedObject.save() associatedObject.save()
.success(function() { customEventEmitter.emit('success', associatedObject) }) .success(function() { customEventEmitter.emit('success', associatedObject) })
.error(function(err) { customEventEmitter.emit('failure', err) }) .error(function(err) { customEventEmitter.emit('error', err) })
}) })
}) })
return customEventEmitter.run() return customEventEmitter.run()
...@@ -70,4 +70,4 @@ module.exports = (function() { ...@@ -70,4 +70,4 @@ module.exports = (function() {
} }
return HasOne return HasOne
})() })()
\ No newline at end of file
...@@ -68,12 +68,12 @@ module.exports = (function() { ...@@ -68,12 +68,12 @@ module.exports = (function() {
self.QueryInterface self.QueryInterface
.createTable(self.tableName, self.attributes, options) .createTable(self.tableName, self.attributes, options)
.success(function() { emitter.emit('success', self) }) .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) }) .on('sql', function(sql) { emitter.emit('sql', sql) })
} }
if(options.force) 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 else
doQuery() doQuery()
......
...@@ -127,7 +127,7 @@ module.exports = (function() { ...@@ -127,7 +127,7 @@ module.exports = (function() {
var self = this var self = this
this.pool.acquire(function(err, client) { this.pool.acquire(function(err, client) {
if (err) { if (err) {
queueItem.query.emit('failure', err) queueItem.query.emit('error', err)
return return
} }
//we set the client here, asynchronously, when getting a pooled connection //we set the client here, asynchronously, when getting a pooled connection
......
...@@ -90,7 +90,7 @@ module.exports = (function() { ...@@ -90,7 +90,7 @@ module.exports = (function() {
var onFailure = function(err) { var onFailure = function(err) {
unbindClient.call(this) unbindClient.call(this)
this.emit('failure', err, this.callee) this.emit('error', err, this.callee)
} }
return Query return Query
......
...@@ -85,7 +85,7 @@ module.exports = (function() { ...@@ -85,7 +85,7 @@ module.exports = (function() {
query.on('error', function(err) { query.on('error', function(err) {
receivedError = true receivedError = true
self.emit('failure', err, self.callee) self.emit('error', err, self.callee)
}); });
return this return this
......
...@@ -16,7 +16,7 @@ module.exports = (function() { ...@@ -16,7 +16,7 @@ module.exports = (function() {
} }
Query.prototype.failure = Query.prototype.fail = Query.prototype.error = function(fct) { Query.prototype.failure = Query.prototype.fail = Query.prototype.error = function(fct) {
this.on('failure', fct) this.on('error', fct)
return this return this
} }
......
...@@ -108,7 +108,7 @@ module.exports = (function() { ...@@ -108,7 +108,7 @@ module.exports = (function() {
} }
var onFailure = function(err) { var onFailure = function(err) {
this.emit('failure', err, this.callee) this.emit('error', err, this.callee)
} }
return Query return Query
......
...@@ -29,14 +29,14 @@ module.exports = (function() { ...@@ -29,14 +29,14 @@ module.exports = (function() {
CustomEventEmitter.prototype.fail = CustomEventEmitter.prototype.fail =
CustomEventEmitter.prototype.error = CustomEventEmitter.prototype.error =
function(fct) { function(fct) {
this.on('failure', fct) this.on('error', fct)
return this return this
} }
CustomEventEmitter.prototype.done = CustomEventEmitter.prototype.done =
CustomEventEmitter.prototype.complete = CustomEventEmitter.prototype.complete =
function(fct) { 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) }) .on('success', function(result) { fct(null, result) })
return this return this
} }
......
...@@ -11,7 +11,7 @@ module.exports = (function(){ ...@@ -11,7 +11,7 @@ module.exports = (function(){
NullEmitter.prototype.emitNull = function() { NullEmitter.prototype.emitNull = function() {
this.emit('success', null) this.emit('success', null)
this.emit('failure', null) this.emit('error', null)
} }
return NullEmitter return NullEmitter
......
...@@ -43,7 +43,7 @@ module.exports = (function() { ...@@ -43,7 +43,7 @@ module.exports = (function() {
return new Utils.CustomEventEmitter(function(emitter) { return new Utils.CustomEventEmitter(function(emitter) {
self.getUndoneMigrations(function(err, migrations) { self.getUndoneMigrations(function(err, migrations) {
if(err) { if(err) {
emitter.emit('failure', err) emitter.emit('error', err)
} else { } else {
var chainer = new Utils.QueryChainer var chainer = new Utils.QueryChainer
, from = migrations[0] , from = migrations[0]
...@@ -75,7 +75,7 @@ module.exports = (function() { ...@@ -75,7 +75,7 @@ module.exports = (function() {
chainer chainer
.runSerially({ skipOnError: true }) .runSerially({ skipOnError: true })
.success(function() { emitter.emit('success', null) }) .success(function() { emitter.emit('success', null) })
.error(function(err) { emitter.emit('failure', err) }) .error(function(err) { emitter.emit('error', err) })
} }
}) })
}).run() }).run()
...@@ -152,7 +152,7 @@ module.exports = (function() { ...@@ -152,7 +152,7 @@ module.exports = (function() {
SequelizeMeta SequelizeMeta
.sync(syncOptions || {}) .sync(syncOptions || {})
.success(function() { emitter.emit('success', SequelizeMeta) }) .success(function() { emitter.emit('success', SequelizeMeta) })
.error(function(err) { emitter.emit('failure', err) }) .error(function(err) { emitter.emit('error', err) })
} else { } else {
emitter.emit('success', SequelizeMeta) emitter.emit('success', SequelizeMeta)
} }
...@@ -168,7 +168,7 @@ module.exports = (function() { ...@@ -168,7 +168,7 @@ module.exports = (function() {
self.findOrCreateSequelizeMetaDAO().success(function(SequelizeMeta) { self.findOrCreateSequelizeMetaDAO().success(function(SequelizeMeta) {
SequelizeMeta.find({ order: 'id DESC' }).success(function(meta) { SequelizeMeta.find({ order: 'id DESC' }).success(function(meta) {
emitter.emit('success', meta ? meta : null) 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) }) }).error(function(err) { emitter.emit(err) })
}).run() }).run()
} }
...@@ -182,7 +182,7 @@ module.exports = (function() { ...@@ -182,7 +182,7 @@ module.exports = (function() {
emitter.emit('success', meta ? meta.to : null) emitter.emit('success', meta ? meta.to : null)
}) })
.error(function(err) { .error(function(err) {
emitter.emit('failure', err) emitter.emit('error', err)
}) })
}).run() }).run()
} }
......
...@@ -116,7 +116,7 @@ module.exports = (function() { ...@@ -116,7 +116,7 @@ module.exports = (function() {
this.finished = (this.finishedEmits == this.serials.length) this.finished = (this.finishedEmits == this.serials.length)
if(this.finished && this.wasRunning) { 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) , result = (this.fails.length == 0 ? result : this.fails)
this.eventEmitter.emit(status, result) this.eventEmitter.emit(status, result)
......
...@@ -48,11 +48,11 @@ module.exports = (function() { ...@@ -48,11 +48,11 @@ module.exports = (function() {
}) })
.error(function(err) { .error(function(err) {
self.emit('dropAllTables', err) self.emit('dropAllTables', err)
emitter.emit('failure', err) emitter.emit('error', err)
}) })
}).error(function(err) { }).error(function(err) {
self.emit('dropAllTables', err) self.emit('dropAllTables', err)
emitter.emit('failure', err) emitter.emit('error', err)
}) })
}).run() }).run()
} }
...@@ -72,7 +72,7 @@ module.exports = (function() { ...@@ -72,7 +72,7 @@ module.exports = (function() {
emitter.emit('success', Utils._.flatten(tableNames)) emitter.emit('success', Utils._.flatten(tableNames))
}).error(function(err) { }).error(function(err) {
self.emit('showAllTables', err) self.emit('showAllTables', err)
emitter.emit('failure', err) emitter.emit('error', err)
}) })
}).run() }).run()
} }
...@@ -90,7 +90,7 @@ module.exports = (function() { ...@@ -90,7 +90,7 @@ module.exports = (function() {
self.sequelize.query(sql, null, { raw: true }).success(function(data) { self.sequelize.query(sql, null, { raw: true }).success(function(data) {
emitter.emit('success', data) emitter.emit('success', data)
}).error(function(err) { }).error(function(err) {
emitter.emit('failure', err) emitter.emit('error', err)
}) })
}).run() }).run()
} }
...@@ -153,11 +153,11 @@ module.exports = (function() { ...@@ -153,11 +153,11 @@ module.exports = (function() {
emitter.emit('success', null) emitter.emit('success', null)
}).error(function(err) { }).error(function(err) {
self.emit('renameColumn', err) self.emit('renameColumn', err)
emitter.emit('failure', err) emitter.emit('error', err)
}) })
}).error(function(err) { }).error(function(err) {
self.emit('renameColumn', err) self.emit('renameColumn', err)
emitter.emit('failure', err) emitter.emit('error', err)
}) })
}).run() }).run()
} }
...@@ -217,7 +217,7 @@ module.exports = (function() { ...@@ -217,7 +217,7 @@ module.exports = (function() {
}) })
.error(function(err) { .error(function(err) {
self.emit('rawSelect', err) self.emit('rawSelect', err)
emitter.emit('failure', err) emitter.emit('error', err)
}) })
qry.on('sql', function(sql) { qry.on('sql', function(sql) {
emitter.emit('sql', sql) emitter.emit('sql', sql)
...@@ -253,7 +253,7 @@ module.exports = (function() { ...@@ -253,7 +253,7 @@ module.exports = (function() {
}).error(function(err) { }).error(function(err) {
options.error && options.error(err) options.error && options.error(err)
self.emit(methodName, err) self.emit(methodName, err)
emitter.emit('failure', err) emitter.emit('error', err)
}) })
query.on('sql', function(sql) { query.on('sql', function(sql) {
emitter.emit('sql', sql) emitter.emit('sql', sql)
......
...@@ -115,7 +115,7 @@ module.exports = (function() { ...@@ -115,7 +115,7 @@ module.exports = (function() {
chainer chainer
.run() .run()
.success(function() { emitter.emit('success', null) }) .success(function() { emitter.emit('success', null) })
.error(function(err) { emitter.emit('failure', err) }) .error(function(err) { emitter.emit('error', err) })
}).run() }).run()
} }
...@@ -130,7 +130,7 @@ module.exports = (function() { ...@@ -130,7 +130,7 @@ module.exports = (function() {
chainer chainer
.run() .run()
.success(function() { emitter.emit('success', null) }) .success(function() { emitter.emit('success', null) })
.error(function(err) { emitter.emit('failure', err) }) .error(function(err) { emitter.emit('error', err) })
}).run() }).run()
} }
......
...@@ -16,7 +16,7 @@ Factories.prototype.DAO = function(daoName, options, callback, count) { ...@@ -16,7 +16,7 @@ Factories.prototype.DAO = function(daoName, options, callback, count) {
DAO.create(options).on('success', function(dao) { DAO.create(options).on('success', function(dao) {
daos.push(dao) daos.push(dao)
cb && cb() cb && cb()
}).on('failure', function(err) { }).on('error', function(err) {
console.log(err) console.log(err)
done() done()
}) })
......
...@@ -21,7 +21,7 @@ Helpers.prototype.drop = function() { ...@@ -21,7 +21,7 @@ Helpers.prototype.drop = function() {
self.sequelize self.sequelize
.drop() .drop()
.on('success', done) .on('success', done)
.on('failure', function(err) { console.log(err) }) .on('error', function(err) { console.log(err) })
}) })
} }
......
...@@ -161,7 +161,7 @@ describe('DAOFactory', function() { ...@@ -161,7 +161,7 @@ describe('DAOFactory', function() {
User.all().on('success', function(users) { User.all().on('success', function(users) {
done() done()
expect(users.length).toEqual(2) expect(users.length).toEqual(2)
}).on('failure', function(err) { console.log(err) }) }).on('error', function(err) { console.log(err) })
}) })
}) })
}) })
......
...@@ -16,7 +16,7 @@ Factories.prototype.DAO = function(daoName, options, callback, count) { ...@@ -16,7 +16,7 @@ Factories.prototype.DAO = function(daoName, options, callback, count) {
DAO.create(options).on('success', function(dao) { DAO.create(options).on('success', function(dao) {
daos.push(dao) daos.push(dao)
cb && cb() cb && cb()
}).on('failure', function(err) { }).on('error', function(err) {
console.log(err) console.log(err)
done() done()
}) })
......
...@@ -21,7 +21,7 @@ Helpers.prototype.drop = function() { ...@@ -21,7 +21,7 @@ Helpers.prototype.drop = function() {
self.sequelize self.sequelize
.drop() .drop()
.on('success', done) .on('success', done)
.on('failure', function(err) { console.log(err) }) .on('error', function(err) { console.log(err) })
}) })
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!