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

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(",") var query = "INSERT INTO " + table + " (" + attributes + ") VALUES " + tuples.join(",") + ";"
}
return Utils._.template(query)(replacements) 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) var query = "DELETE FROM " + table + " WHERE " + where
}
return Utils._.template(query)(replacements) return query
}, },
incrementQuery: function (tableName, attrValueHash, where) { incrementQuery: function (tableName, attrValueHash, where) {
...@@ -326,7 +323,7 @@ module.exports = (function() { ...@@ -326,7 +323,7 @@ module.exports = (function() {
values.push(QueryGenerator.addQuotes(key) + "=" + QueryGenerator.addQuotes(key) + " + " +Utils.escape(_value)) values.push(QueryGenerator.addQuotes(key) + "=" + QueryGenerator.addQuotes(key) + " + " +Utils.escape(_value))
} }
var table = QueryGenerator.addQuotes(tableName) var table = QueryGenerator.addQuotes(tableName)
var values = values.join(",") var values = values.join(",")
var where = QueryGenerator.getWhereConditions(where) var where = QueryGenerator.getWhereConditions(where)
......
...@@ -116,6 +116,7 @@ module.exports = (function() { ...@@ -116,6 +116,7 @@ module.exports = (function() {
record = this.callee.daoFactory.daoFactoryManager.sequelize.queryInterface.QueryGenerator.toHstore(record) record = this.callee.daoFactory.daoFactoryManager.sequelize.queryInterface.QueryGenerator.toHstore(record)
} }
this.callee[key] = record this.callee[key] = record
}
} }
} }
...@@ -129,6 +130,7 @@ module.exports = (function() { ...@@ -129,6 +130,7 @@ module.exports = (function() {
record = this.callee.daoFactory.daoFactoryManager.sequelize.queryInterface.QueryGenerator.toHstore(record) record = this.callee.daoFactory.daoFactoryManager.sequelize.queryInterface.QueryGenerator.toHstore(record)
} }
this.callee[key] = record this.callee[key] = record
}
} }
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!