fix mssql import (+integration test)

This commit is contained in:
Jan Prochazka
2022-06-09 14:57:08 +02:00
parent 77b85fa42b
commit 13d778586e
3 changed files with 52 additions and 41 deletions

View File

@@ -1,21 +1,21 @@
version: '3'
services:
postgres:
image: postgres
restart: always
environment:
POSTGRES_PASSWORD: Pwd2020Db
ports:
- 15000:5432
# postgres:
# image: postgres
# restart: always
# environment:
# POSTGRES_PASSWORD: Pwd2020Db
# ports:
# - 15000:5432
mariadb:
image: mariadb
command: --default-authentication-plugin=mysql_native_password
restart: always
ports:
- 15004:3306
environment:
- MYSQL_ROOT_PASSWORD=Pwd2020Db
# mariadb:
# image: mariadb
# command: --default-authentication-plugin=mysql_native_password
# restart: always
# ports:
# - 15004:3306
# environment:
# - MYSQL_ROOT_PASSWORD=Pwd2020Db
# mysql:
# image: mysql:8.0.18
@@ -26,15 +26,15 @@ services:
# environment:
# - MYSQL_ROOT_PASSWORD=Pwd2020Db
# mssql:
# image: mcr.microsoft.com/mssql/server
# restart: always
# ports:
# - 15002:1433
# environment:
# - ACCEPT_EULA=Y
# - SA_PASSWORD=Pwd2020Db
# - MSSQL_PID=Express
mssql:
image: mcr.microsoft.com/mssql/server
restart: always
ports:
- 15002:1433
environment:
- ACCEPT_EULA=Y
- SA_PASSWORD=Pwd2020Db
- MSSQL_PID=Express
# cockroachdb:
# image: cockroachdb/cockroach

View File

@@ -135,8 +135,8 @@ const filterLocal = [
// filter local testing
'-MySQL',
'-MariaDB',
'PostgreSQL',
'-SQL Server',
'-PostgreSQL',
'SQL Server',
'-SQLite',
'-CockroachDB',
];

View File

@@ -1,6 +1,7 @@
const { createBulkInsertStreamBase } = require('dbgate-tools');
const tedious = require('tedious');
const getConcreteType = require('./getConcreteType');
const _ = require('lodash');
function runBulkInsertBatch(pool, tableName, writable, rows) {
return new Promise((resolve, reject) => {
@@ -12,24 +13,34 @@ function runBulkInsertBatch(pool, tableName, writable, rows) {
else resolve();
});
for (const column of writable.columnNames) {
const tcol = writable.templateColumns.find((x) => x.columnName == column);
const stringColumns = new Set();
bulkLoad.addColumn(
column,
tcol
? getConcreteType(tcol.driverNativeColumn.type, tcol.driverNativeColumn.dataLength)
: tedious.TYPES.NVarChar,
{
nullable: tcol ? !tcol.notNull : true,
length: tcol ? tcol.driverNativeColumn.dataLength : undefined,
precision: tcol ? tcol.driverNativeColumn.precision : undefined,
scale: tcol ? tcol.driverNativeColumn.scale : undefined,
}
);
for (const column of writable.columnNames) {
const tcol = writable.templateColumns.find(x => x.columnName == column);
const type = tcol
? getConcreteType(tcol.driverNativeColumn.type, tcol.driverNativeColumn.dataLength)
: tedious.TYPES.NVarChar;
if (type.type.toLowerCase().includes('char')) stringColumns.add(column);
bulkLoad.addColumn(column, type, {
nullable: tcol ? !tcol.notNull : true,
length: tcol ? tcol.driverNativeColumn.dataLength : undefined,
precision: tcol ? tcol.driverNativeColumn.precision : undefined,
scale: tcol ? tcol.driverNativeColumn.scale : undefined,
});
}
pool.execBulkLoad(bulkLoad, rows);
const rowsMapped = rows.map(row =>
_.mapValues(row, (v, k) => {
if (stringColumns.has(k)) return v ? v.toString() : null;
return v;
})
);
// console.log('IMPORT ROWS', rowsMapped);
pool.execBulkLoad(bulkLoad, rowsMapped);
});
}