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

Commit e60f8233 by Sascha Depold

changed chainQuery method + allowing deletion if passing limit:null

1 parent 5dce3a5c
Showing with 15 additions and 6 deletions
...@@ -44,22 +44,32 @@ var classMethods = { ...@@ -44,22 +44,32 @@ var classMethods = {
query = "UPDATE %{table} SET %{values} WHERE id = %{id}" query = "UPDATE %{table} SET %{values} WHERE id = %{id}"
break break
case 'delete': case 'delete':
query = "DELETE FROM %{table} WHERE %{where} LIMIT 1" query = "DELETE FROM %{table} WHERE %{where}"
if(values.limit != null) query += " LIMIT 1"
break break
} }
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}]
var executeQuery = function(index) { var executeQuery = function(index) {
queries[index](function() { var queryHash = queries[index]
var method = SequelizeHelper.Hash.keys(queryHash)
var object = queryHash[method]
object[method](function() {
if(queries.length > (index + 1)) if(queries.length > (index + 1))
executeQuery(index + 1) executeQuery(index + 1)
else else
if (callback) callback() if (callback) callback()
}) })
} }
executeQuery(0) if(queries.length > 0)
executeQuery(0)
else
if (callback) callback()
} }
} }
...@@ -80,7 +90,7 @@ Sequelize.prototype = { ...@@ -80,7 +90,7 @@ Sequelize.prototype = {
table.klass.prepareAssociations() table.klass.prepareAssociations()
}) })
if(SequelizeHelper.Hash.keys(tables).length == 0) if(SequelizeHelper.Hash.keys(this.tables).length == 0)
callback() callback()
else else
SequelizeHelper.Hash.forEach(tables, function(table) { SequelizeHelper.Hash.forEach(tables, function(table) {
...@@ -103,7 +113,7 @@ Sequelize.prototype = { ...@@ -103,7 +113,7 @@ Sequelize.prototype = {
table.klass.drop(function() { table.klass.drop(function() {
finished.push(true) finished.push(true)
if(finished.length == SequelizeHelper.Hash.keys(tables).length) if(finished.length == SequelizeHelper.Hash.keys(tables).length)
callback() if(callback) callback()
}) })
}) })
}, },
...@@ -114,7 +124,6 @@ Sequelize.prototype = { ...@@ -114,7 +124,6 @@ Sequelize.prototype = {
var table = new SequelizeTable(this, SequelizeHelper.SQL.asTableName(name), attributes) var table = new SequelizeTable(this, SequelizeHelper.SQL.asTableName(name), attributes)
table.attributes = attributes table.attributes = attributes
this.tables[name] = {klass: table, attributes: attributes} this.tables[name] = {klass: table, attributes: attributes}
table.sequelize = this table.sequelize = this
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!