mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-17 23:45:59 +00:00
SYNC: fixes
This commit is contained in:
committed by
Diflow
parent
20a1cc89ae
commit
805a063fa1
@@ -74,9 +74,9 @@ services:
|
||||
# - cockroachdb
|
||||
# restart: on-failure
|
||||
|
||||
# oracle:
|
||||
# image: gvenzl/oracle-xe:21-slim
|
||||
# environment:
|
||||
# ORACLE_PASSWORD: Pwd2020Db
|
||||
# ports:
|
||||
# - 15006:1521
|
||||
oracle:
|
||||
image: gvenzl/oracle-xe:21-slim
|
||||
environment:
|
||||
ORACLE_PASSWORD: Pwd2020Db
|
||||
ports:
|
||||
- 15006:1521
|
||||
|
||||
@@ -52,7 +52,7 @@ async function importDbFromFolder({ connection, systemConnection, driver, folder
|
||||
// console.log('CREATING STRUCTURE:', sql);
|
||||
await executeQuery({ connection, systemConnection: dbhan, driver, sql, logScriptItems: true });
|
||||
|
||||
for (const table of model.tables) {
|
||||
for (const table of modelAdapted.tables) {
|
||||
const fileName = path.join(folder, `${table.pureName}.jsonl`);
|
||||
if (await fs.exists(fileName)) {
|
||||
const src = await jsonLinesReader({ fileName });
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -139,6 +139,16 @@ class Dumper extends SqlDumper {
|
||||
// putByteArrayValue(value) {
|
||||
// this.putRaw(`e'\\\\x${arrayToHexString(value)}'`);
|
||||
// }
|
||||
|
||||
putValue(value, dataType) {
|
||||
if (dataType?.toLowerCase() == 'timestamp') {
|
||||
this.putRaw(`TO_TIMESTAMP('${value}', 'YYYY-MM-DD"T"HH24:MI:SS')`);
|
||||
} else if (dataType?.toLowerCase() == 'date') {
|
||||
this.putRaw(`TO_DATE('${value}', 'YYYY-MM-DD"T"HH24:MI:SS')`);
|
||||
} else {
|
||||
super.putValue(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Dumper;
|
||||
|
||||
Reference in New Issue
Block a user