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

Commit cdd839d0 by Joel Trost Committed by Matt Broadstone

alias checks for bulk insert

1 parent cbf8fa1a
Showing with 24 additions and 6 deletions
......@@ -152,16 +152,33 @@ module.exports = (function() {
Parameters: table name + list of hashes of attribute-value-pairs.
*/
/* istanbul ignore next */
bulkInsertQuery: function(tableName, attrValueHashes,options, attributes) {
bulkInsertQuery: function(tableName, attrValueHashes,options, attributes) {
var query = '',
allAttributes = [],
insertKey = false,
isEmpty = true,
ignoreKeys = options.fields;
ignoreKeys = [];
for(var key in attributes){
//console.log('some more action', attributes.deletedAtThisTime);
var aliasKey = attributes[key].field || key;
if(ignoreKeys.indexOf(aliasKey) < 0){
ignoreKeys.push(aliasKey);
}
if(attributes[key].primaryKey){
for(var i = 0; i < attrValueHashes.length; i++){
if(aliasKey in attrValueHashes[i]){
delete attrValueHashes[i][aliasKey];
}
}
}
}
Utils._.forEach(attrValueHashes, function(attrValueHash, i) {
Utils._.forOwn(attrValueHash, function(value, key, hash) {
if (allAttributes.indexOf(key) === -1) allAttributes.push(key);
var aliasKey = attributes[key].field || key;
if (value !== null && ignoreKeys.indexOf(key) > -1){
ignoreKeys.splice(ignoreKeys.indexOf(key),1);
}else if(value !== null && attributes[key].autoIncrement){
insertKey = true;
......@@ -173,21 +190,22 @@ module.exports = (function() {
});
if(!isEmpty){
for(var i = 0; i < ignoreKeys.length; i++){
allAttributes.splice(allAttributes.indexOf(ignoreKeys[i]), 1);
for(var j = 0; j < ignoreKeys.length; j++){
if(allAttributes.indexOf(ignoreKeys[j]) > -1){
allAttributes.splice(allAttributes.indexOf(ignoreKeys[j]), 1);
}
}
query = SqlGenerator.bulkInsertSql(tableName, allAttributes, attrValueHashes,options);
if(insertKey){
query = SqlGenerator.identityInsertWrapper(query, tableName);
}
}else{
for(var j = 0; j < attrValueHashes.length; j++){
for(var k = 0; k < attrValueHashes.length; k++){
query += SqlGenerator.insertSql(tableName);
}
}
return query;
},
/*
Returns an update query.
Parameters:
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!