Comparing version 1.0.3 to 1.0.4
@@ -95,1 +95,49 @@ "use strict"; | ||
}; | ||
TdmBulkLoad.prototype.getMergeSql = function (targetTable, matchColumns, options) | ||
{ | ||
var update = options.update || false; | ||
var insert = options.insert || false; | ||
var tgt = 'tgt'; | ||
var tmp = 'tmp'; | ||
if (!(matchColumns instanceof Array)) | ||
matchColumns = [ matchColumns ]; | ||
var sql = 'MERGE ' + targetTable + ' ' + tgt + ' USING ' + this.tediousBulkLoad.table + ' ' + tmp + | ||
'\nON (' + matchColumns.map(function (c) { return tgt + '.' + c + '=' + tmp + '.' + c; }).join(' AND ') + ')'; | ||
var i; | ||
var cols = this.tediousBulkLoad.columns; | ||
var columnNames = []; | ||
for (i = 0; i < cols.length; i++) | ||
columnNames.push(cols[i].name); | ||
if (insert) | ||
{ | ||
sql += '\nWHEN NOT MATCHED BY TARGET THEN INSERT ' + | ||
'\n(' + columnNames.join(',') + ')' + | ||
'\nVALUES (' + columnNames.map(function (c) { return tmp + '.' + c; }).join(',') + ')'; | ||
} | ||
if (update) | ||
{ | ||
sql += '\nWHEN MATCHED THEN UPDATE SET\n'; | ||
var comma = false; | ||
for (i = 0; i < columnNames.length; i++) | ||
{ | ||
if (matchColumns.indexOf(columnNames[i]) !== -1) | ||
continue; | ||
if (comma) | ||
sql += ','; | ||
else | ||
comma = true; | ||
sql += tgt + '.' + columnNames[i] + '=' + tmp + '.' + columnNames[i]; | ||
} | ||
} | ||
return sql + ';'; | ||
}; |
{ | ||
"name": "tedium", | ||
"description": "A generator-based wrapper for Tedious to make it easier to work with.", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"author": "Bret Copeland <bret@atlantisflight.org>", | ||
@@ -6,0 +6,0 @@ "main": "./lib/Tedium.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
23890
475