introduced dbhandle instead of overwriting 3rd party client's fields

This commit is contained in:
SPRINX0\prochazka
2024-09-20 10:27:03 +02:00
parent 6b8b511d0d
commit 48d4374346
26 changed files with 387 additions and 371 deletions

View File

@@ -3,12 +3,12 @@ const tedious = require('tedious');
const getConcreteType = require('./getConcreteType');
const _ = require('lodash');
function runBulkInsertBatch(pool, tableName, writable, rows) {
function runBulkInsertBatch(dbhan, tableName, writable, rows) {
return new Promise((resolve, reject) => {
var options = { keepNulls: true };
// instantiate - provide the table where you'll be inserting to, options and a callback
var bulkLoad = pool.newBulkLoad(tableName, options, (error, rowCount) => {
var bulkLoad = dbhan.client.newBulkLoad(tableName, options, (error, rowCount) => {
if (error) reject(error);
else resolve();
});
@@ -40,7 +40,7 @@ function runBulkInsertBatch(pool, tableName, writable, rows) {
);
// console.log('IMPORT ROWS', rowsMapped);
pool.execBulkLoad(bulkLoad, rowsMapped);
dbhan.client.execBulkLoad(bulkLoad, rowsMapped);
});
}
@@ -48,8 +48,8 @@ function runBulkInsertBatch(pool, tableName, writable, rows) {
*
* @param {import('dbgate-types').EngineDriver} driver
*/
function createTediousBulkInsertStream(driver, stream, pool, name, options) {
const writable = createBulkInsertStreamBase(driver, stream, pool, name, options);
function createTediousBulkInsertStream(driver, stream, dbhan, name, options) {
const writable = createBulkInsertStreamBase(driver, stream, dbhan, name, options);
const fullName = name.schemaName ? `[${name.schemaName}].[${name.pureName}]` : name.pureName;
@@ -59,7 +59,7 @@ function createTediousBulkInsertStream(driver, stream, pool, name, options) {
? `${driver.dialect.quoteIdentifier(name.schemaName)}.${driver.dialect.quoteIdentifier(name.pureName)}`
: driver.dialect.quoteIdentifier(name.pureName);
const respTemplate = await driver.query(pool, `SELECT * FROM ${fullNameQuoted} WHERE 1=0`, {
const respTemplate = await driver.query(dbhan, `SELECT * FROM ${fullNameQuoted} WHERE 1=0`, {
addDriverNativeColumn: true,
});
writable.templateColumns = respTemplate.columns;
@@ -68,7 +68,7 @@ function createTediousBulkInsertStream(driver, stream, pool, name, options) {
const rows = writable.buffer;
writable.buffer = [];
await runBulkInsertBatch(pool, fullName, writable, rows);
await runBulkInsertBatch(dbhan, fullName, writable, rows);
};
return writable;