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

Commit b4d0b9bd by Sascha Depold

added possibility to pass params to chainQueries method

1 parent 43f3efa9
Showing with 10 additions and 14 deletions
...@@ -53,23 +53,20 @@ var classMethods = { ...@@ -53,23 +53,20 @@ var classMethods = {
return SequelizeHelper.evaluateTemplate(query, values) return SequelizeHelper.evaluateTemplate(query, values)
}, },
chainQueries: function(queries, callback) { chainQueries: function(queries, callback) {
// queries = [{method: object}, {method: object}, {method: object}] // queries = [{method: object}, {method: object, params: [1,2,3]}, {method: object}]
var executeQuery = function(index) { var executeQuery = function(index) {
var queryHash = queries[index] var queryHash = queries[index]
var method = SequelizeHelper.Hash.keys(queryHash) var method = SequelizeHelper.Array.without(SequelizeHelper.Hash.keys(queryHash), "params")[0]
var object = queryHash[method] var object = queryHash[method]
var iterator = function() {
if(queries.length > (index + 1)) executeQuery(index + 1)
else if (callback) callback()
}
object[method](function() { object[method].apply(object, SequelizeHelper.Array.join(queryHash.params || [], [iterator]))
if(queries.length > (index + 1))
executeQuery(index + 1)
else
if (callback) callback()
})
} }
if(queries.length > 0) if(queries.length > 0) executeQuery(0)
executeQuery(0) else if (callback) callback()
else
if (callback) callback()
} }
} }
...@@ -106,8 +103,7 @@ Sequelize.prototype = { ...@@ -106,8 +103,7 @@ Sequelize.prototype = {
var finished = [] var finished = []
var tables = this.tables var tables = this.tables
if(SequelizeHelper.Hash.keys(tables).length == 0) if((SequelizeHelper.Hash.keys(tables).length == 0) && callback) callback()
callback()
else else
SequelizeHelper.Hash.forEach(tables, function(table, tableName) { SequelizeHelper.Hash.forEach(tables, function(table, tableName) {
table.klass.drop(function() { table.klass.drop(function() {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!