mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-30 13:53:59 +00:00
SYNC: fixes
This commit is contained in:
committed by
Diflow
parent
20a1cc89ae
commit
805a063fa1
@@ -74,9 +74,9 @@ services:
|
|||||||
# - cockroachdb
|
# - cockroachdb
|
||||||
# restart: on-failure
|
# restart: on-failure
|
||||||
|
|
||||||
# oracle:
|
oracle:
|
||||||
# image: gvenzl/oracle-xe:21-slim
|
image: gvenzl/oracle-xe:21-slim
|
||||||
# environment:
|
environment:
|
||||||
# ORACLE_PASSWORD: Pwd2020Db
|
ORACLE_PASSWORD: Pwd2020Db
|
||||||
# ports:
|
ports:
|
||||||
# - 15006:1521
|
- 15006:1521
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ async function importDbFromFolder({ connection, systemConnection, driver, folder
|
|||||||
// console.log('CREATING STRUCTURE:', sql);
|
// console.log('CREATING STRUCTURE:', sql);
|
||||||
await executeQuery({ connection, systemConnection: dbhan, driver, sql, logScriptItems: true });
|
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`);
|
const fileName = path.join(folder, `${table.pureName}.jsonl`);
|
||||||
if (await fs.exists(fileName)) {
|
if (await fs.exists(fileName)) {
|
||||||
const src = await jsonLinesReader({ fileName });
|
const src = await jsonLinesReader({ fileName });
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { EngineDriver, WriteTableOptions } from 'dbgate-types';
|
import { EngineDriver, WriteTableOptions } from 'dbgate-types';
|
||||||
import _intersection from 'lodash/intersection';
|
import _intersection from 'lodash/intersection';
|
||||||
|
import _fromPairs from 'lodash/fromPairs';
|
||||||
import { getLogger } from './getLogger';
|
import { getLogger } from './getLogger';
|
||||||
import { prepareTableForImport } from './tableTransforms';
|
import { prepareTableForImport } from './tableTransforms';
|
||||||
|
|
||||||
@@ -18,6 +19,7 @@ export function createBulkInsertStreamBase(driver: EngineDriver, stream, dbhan,
|
|||||||
writable.buffer = [];
|
writable.buffer = [];
|
||||||
writable.structure = null;
|
writable.structure = null;
|
||||||
writable.columnNames = null;
|
writable.columnNames = null;
|
||||||
|
writable.columnDataTypes = null;
|
||||||
writable.requireFixedStructure = driver.databaseEngineTypes.includes('sql');
|
writable.requireFixedStructure = driver.databaseEngineTypes.includes('sql');
|
||||||
|
|
||||||
writable.addRow = async row => {
|
writable.addRow = async row => {
|
||||||
@@ -58,6 +60,12 @@ export function createBulkInsertStreamBase(driver: EngineDriver, stream, dbhan,
|
|||||||
structure.columns.map(x => x.columnName),
|
structure.columns.map(x => x.columnName),
|
||||||
writable.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 () => {
|
writable.send = async () => {
|
||||||
@@ -74,7 +82,9 @@ export function createBulkInsertStreamBase(driver: EngineDriver, stream, dbhan,
|
|||||||
for (const row of rows) {
|
for (const row of rows) {
|
||||||
if (wasRow) dmp.putRaw(',\n');
|
if (wasRow) dmp.putRaw(',\n');
|
||||||
dmp.putRaw('(');
|
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(')');
|
dmp.putRaw(')');
|
||||||
wasRow = true;
|
wasRow = true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -139,6 +139,16 @@ class Dumper extends SqlDumper {
|
|||||||
// putByteArrayValue(value) {
|
// putByteArrayValue(value) {
|
||||||
// this.putRaw(`e'\\\\x${arrayToHexString(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;
|
module.exports = Dumper;
|
||||||
|
|||||||
Reference in New Issue
Block a user