mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-18 21:55:59 +00:00
SYNC: fixes
This commit is contained in:
committed by
Diflow
parent
20a1cc89ae
commit
805a063fa1
@@ -1,5 +1,6 @@
|
||||
import { EngineDriver, WriteTableOptions } from 'dbgate-types';
|
||||
import _intersection from 'lodash/intersection';
|
||||
import _fromPairs from 'lodash/fromPairs';
|
||||
import { getLogger } from './getLogger';
|
||||
import { prepareTableForImport } from './tableTransforms';
|
||||
|
||||
@@ -18,6 +19,7 @@ export function createBulkInsertStreamBase(driver: EngineDriver, stream, dbhan,
|
||||
writable.buffer = [];
|
||||
writable.structure = null;
|
||||
writable.columnNames = null;
|
||||
writable.columnDataTypes = null;
|
||||
writable.requireFixedStructure = driver.databaseEngineTypes.includes('sql');
|
||||
|
||||
writable.addRow = async row => {
|
||||
@@ -58,6 +60,12 @@ export function createBulkInsertStreamBase(driver: EngineDriver, stream, dbhan,
|
||||
structure.columns.map(x => x.columnName),
|
||||
writable.structure.columns.map(x => x.columnName)
|
||||
);
|
||||
writable.columnDataTypes = _fromPairs(
|
||||
writable.columnNames.map(colName => [
|
||||
colName,
|
||||
writable.structure.columns.find(x => x.columnName == colName)?.dataType,
|
||||
])
|
||||
);
|
||||
};
|
||||
|
||||
writable.send = async () => {
|
||||
@@ -74,7 +82,9 @@ export function createBulkInsertStreamBase(driver: EngineDriver, stream, dbhan,
|
||||
for (const row of rows) {
|
||||
if (wasRow) dmp.putRaw(',\n');
|
||||
dmp.putRaw('(');
|
||||
dmp.putCollection(',', writable.columnNames, col => dmp.putValue(row[col as string]));
|
||||
dmp.putCollection(',', writable.columnNames, col =>
|
||||
dmp.putValue(row[col as string], writable.columnDataTypes?.[col as string])
|
||||
);
|
||||
dmp.putRaw(')');
|
||||
wasRow = true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user