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

Commit d2e9adcb by Martin Aspeli

Rebase onto sequelize master and reflect MySQL query generator refactoring there

1 parent 3b951e13
...@@ -244,8 +244,7 @@ module.exports = (function() { ...@@ -244,8 +244,7 @@ module.exports = (function() {
}, },
bulkInsertQuery: function(tableName, attrValueHashes) { bulkInsertQuery: function(tableName, attrValueHashes) {
var query = "INSERT INTO <%= table %> (<%= attributes %>) VALUES <%= tuples %>;" var tuples = []
, tuples = []
Utils._.forEach(attrValueHashes, function(attrValueHash) { Utils._.forEach(attrValueHashes, function(attrValueHash) {
tuples.push("(" + tuples.push("(" +
...@@ -255,13 +254,12 @@ module.exports = (function() { ...@@ -255,13 +254,12 @@ module.exports = (function() {
")") ")")
}) })
var replacements = { var table = QueryGenerator.addQuotes(tableName)
table: QueryGenerator.addQuotes(tableName), var attributes = Object.keys(attrValueHashes[0]).map(function(attr){return QueryGenerator.addQuotes(attr)}).join(",")
attributes: Object.keys(attrValueHashes[0]).map(function(attr){return QueryGenerator.addQuotes(attr)}).join(","),
tuples: tuples.join(",")
}
return Utils._.template(query)(replacements) var query = "INSERT INTO " + table + " (" + attributes + ") VALUES " + tuples.join(",") + ";"
return query
}, },
updateQuery: function(tableName, attrValueHash, where) { updateQuery: function(tableName, attrValueHash, where) {
...@@ -306,13 +304,12 @@ module.exports = (function() { ...@@ -306,13 +304,12 @@ module.exports = (function() {
bulkDeleteQuery: function(tableName, where, options) { bulkDeleteQuery: function(tableName, where, options) {
options = options || {} options = options || {}
var query = "DELETE FROM <%= table %> WHERE <%= where %>" var table = QueryGenerator.addQuotes(tableName)
var replacements = { var where = QueryGenerator.getWhereConditions(where)
table: QueryGenerator.addQuotes(tableName),
where: QueryGenerator.getWhereConditions(where)
}
return Utils._.template(query)(replacements) var query = "DELETE FROM " + table + " WHERE " + where
return query
}, },
incrementQuery: function (tableName, attrValueHash, where) { incrementQuery: function (tableName, attrValueHash, where) {
......
...@@ -118,6 +118,7 @@ module.exports = (function() { ...@@ -118,6 +118,7 @@ module.exports = (function() {
this.callee[key] = record this.callee[key] = record
} }
} }
}
this.emit('success', this.callee) this.emit('success', this.callee)
} else if (this.send('isUpdateQuery')) { } else if (this.send('isUpdateQuery')) {
...@@ -131,6 +132,7 @@ module.exports = (function() { ...@@ -131,6 +132,7 @@ module.exports = (function() {
this.callee[key] = record this.callee[key] = record
} }
} }
}
this.emit('success', this.callee) this.emit('success', this.callee)
} else { } else {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!