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

Commit cdd839d0 by Joel Trost Committed by Matt Broadstone

alias checks for bulk insert

1 parent cbf8fa1a
Showing with 23 additions and 5 deletions
...@@ -157,11 +157,28 @@ module.exports = (function() { ...@@ -157,11 +157,28 @@ module.exports = (function() {
allAttributes = [], allAttributes = [],
insertKey = false, insertKey = false,
isEmpty = true, 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._.forEach(attrValueHashes, function(attrValueHash, i) {
Utils._.forOwn(attrValueHash, function(value, key, hash) { Utils._.forOwn(attrValueHash, function(value, key, hash) {
if (allAttributes.indexOf(key) === -1) allAttributes.push(key); if (allAttributes.indexOf(key) === -1) allAttributes.push(key);
var aliasKey = attributes[key].field || key;
if (value !== null && ignoreKeys.indexOf(key) > -1){ if (value !== null && ignoreKeys.indexOf(key) > -1){
ignoreKeys.splice(ignoreKeys.indexOf(key),1); ignoreKeys.splice(ignoreKeys.indexOf(key),1);
}else if(value !== null && attributes[key].autoIncrement){ }else if(value !== null && attributes[key].autoIncrement){
insertKey = true; insertKey = true;
...@@ -173,21 +190,22 @@ module.exports = (function() { ...@@ -173,21 +190,22 @@ module.exports = (function() {
}); });
if(!isEmpty){ if(!isEmpty){
for(var i = 0; i < ignoreKeys.length; i++){ for(var j = 0; j < ignoreKeys.length; j++){
allAttributes.splice(allAttributes.indexOf(ignoreKeys[i]), 1); if(allAttributes.indexOf(ignoreKeys[j]) > -1){
allAttributes.splice(allAttributes.indexOf(ignoreKeys[j]), 1);
}
} }
query = SqlGenerator.bulkInsertSql(tableName, allAttributes, attrValueHashes,options); query = SqlGenerator.bulkInsertSql(tableName, allAttributes, attrValueHashes,options);
if(insertKey){ if(insertKey){
query = SqlGenerator.identityInsertWrapper(query, tableName); query = SqlGenerator.identityInsertWrapper(query, tableName);
} }
}else{ }else{
for(var j = 0; j < attrValueHashes.length; j++){ for(var k = 0; k < attrValueHashes.length; k++){
query += SqlGenerator.insertSql(tableName); query += SqlGenerator.insertSql(tableName);
} }
} }
return query; return query;
}, },
/* /*
Returns an update query. Returns an update query.
Parameters: Parameters:
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!