imp exp configurator

This commit is contained in:
Jan Prochazka
2020-06-18 11:42:02 +02:00
parent a9ce93cd67
commit 3f40996d2d
4 changed files with 111 additions and 27 deletions

View File

@@ -3,6 +3,7 @@ import ScriptWriter from './ScriptWriter';
import getAsArray from '../utility/getAsArray';
import { getConnectionInfo } from '../utility/metadataLoaders';
import engines from '@dbgate/engines';
import { findObjectLike } from '@dbgate/datalib';
import { quoteFullName, fullNameFromString } from '@dbgate/datalib';
export default async function createImpExpScript(values) {
@@ -41,3 +42,48 @@ export default async function createImpExpScript(values) {
}
return script.s;
}
export function getTargetName(source, values) {
const key = `targetName_${source}`;
if (values[key]) return values[key];
if (values.targetStorageType == 'csv') return `${source}.csv`;
if (values.targetStorageType == 'jsonl') return `${source}.jsonl`;
return source;
}
export function getActionOptions(source, values,targetDbinfo) {
const res = [];
const targetName = getTargetName(source, values);
if (values.targetStorageType == 'database') {
let existing = findObjectLike(
{ schemaName: values.targetSchemaName, pureName: targetName },
targetDbinfo,
'tables'
);
if (existing) {
res.push({
label: 'Append data',
value: 'appendData',
});
res.push({
label: 'Truncate and import',
value: 'truncate',
});
res.push({
label: 'Drop and create table',
value: 'dropCreateTable',
});
} else {
res.push({
label: 'Create table',
value: 'createTable',
});
}
} else {
res.push({
label: 'Create file',
value: 'createFile',
});
}
return res;
}