mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-05-01 05:03:57 +00:00
json export in configurator, prepare for table mapping
This commit is contained in:
@@ -13,6 +13,9 @@ import {
|
|||||||
FormTablesSelect,
|
FormTablesSelect,
|
||||||
} from '../utility/forms';
|
} from '../utility/forms';
|
||||||
import { useConnectionList, useDatabaseList } from '../utility/metadataLoaders';
|
import { useConnectionList, useDatabaseList } from '../utility/metadataLoaders';
|
||||||
|
import TableControl, { TableColumn } from '../utility/TableControl';
|
||||||
|
|
||||||
|
const Container = styled.div``;
|
||||||
|
|
||||||
const Wrapper = styled.div`
|
const Wrapper = styled.div`
|
||||||
display: flex;
|
display: flex;
|
||||||
@@ -67,7 +70,7 @@ function SourceTargetConfig({ direction, storageTypeField, connectionIdField, da
|
|||||||
const types = [
|
const types = [
|
||||||
{ value: 'database', label: 'Database', directions: ['source'] },
|
{ value: 'database', label: 'Database', directions: ['source'] },
|
||||||
{ value: 'csv', label: 'CSV file(s)', directions: ['target'] },
|
{ value: 'csv', label: 'CSV file(s)', directions: ['target'] },
|
||||||
{ value: 'json', label: 'JSON file(s)', directions: [] },
|
{ value: 'jsonl', label: 'JSON lines file(s)', directions: ['target'] },
|
||||||
];
|
];
|
||||||
const { values } = useFormikContext();
|
const { values } = useFormikContext();
|
||||||
return (
|
return (
|
||||||
@@ -81,16 +84,41 @@ function SourceTargetConfig({ direction, storageTypeField, connectionIdField, da
|
|||||||
<FormConnectionSelect name={connectionIdField} />
|
<FormConnectionSelect name={connectionIdField} />
|
||||||
<Label>Database</Label>
|
<Label>Database</Label>
|
||||||
<FormDatabaseSelect conidName={connectionIdField} name={databaseNameField} />
|
<FormDatabaseSelect conidName={connectionIdField} name={databaseNameField} />
|
||||||
|
{direction == 'source' && (
|
||||||
|
<>
|
||||||
<Label>Tables/views</Label>
|
<Label>Tables/views</Label>
|
||||||
<FormTablesSelect conidName={connectionIdField} databaseName={databaseNameField} name={tablesField} />
|
<FormTablesSelect conidName={connectionIdField} databaseName={databaseNameField} name={tablesField} />
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
</>
|
||||||
|
)}
|
||||||
</Column>
|
</Column>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function ImportExportConfigurator() {
|
export default function ImportExportConfigurator() {
|
||||||
|
const { values } = useFormikContext();
|
||||||
|
const sources = values.sourceTables;
|
||||||
|
const actionOptions = [
|
||||||
|
{
|
||||||
|
label: 'Create file',
|
||||||
|
value: 'createFile',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Create table',
|
||||||
|
value: 'createTable',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Drop and create table',
|
||||||
|
value: 'dropCreateFile',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Append data',
|
||||||
|
value: 'appendData',
|
||||||
|
},
|
||||||
|
];
|
||||||
return (
|
return (
|
||||||
|
<Container>
|
||||||
<Wrapper>
|
<Wrapper>
|
||||||
<SourceTargetConfig
|
<SourceTargetConfig
|
||||||
direction="source"
|
direction="source"
|
||||||
@@ -107,5 +135,14 @@ export default function ImportExportConfigurator() {
|
|||||||
tablesField="targetTables"
|
tablesField="targetTables"
|
||||||
/>
|
/>
|
||||||
</Wrapper>
|
</Wrapper>
|
||||||
|
{/* <TableControl rows={sources || []}>
|
||||||
|
<TableColumn fieldName="source" header="Source" formatter={(row) => row} />
|
||||||
|
<TableColumn
|
||||||
|
fieldName="action"
|
||||||
|
header="Action"
|
||||||
|
formatter={(row) => <FormReactSelect name={`action_${row}`} options={actionOptions} />}
|
||||||
|
/>
|
||||||
|
</TableControl> */}
|
||||||
|
</Container>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,9 +24,16 @@ export default async function createImpExpScript(values) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const targetVar = script.allocVariable();
|
const targetVar = script.allocVariable();
|
||||||
|
if (values.targetStorageType == 'csv') {
|
||||||
script.assign(targetVar, 'csvWriter', {
|
script.assign(targetVar, 'csvWriter', {
|
||||||
fileName: `${fullName.pureName}.csv`,
|
fileName: `${fullName.pureName}.csv`,
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
if (values.targetStorageType == 'jsonl') {
|
||||||
|
script.assign(targetVar, 'jsonLinesWriter', {
|
||||||
|
fileName: `${fullName.pureName}.jsonl`,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
script.copyStream(sourceVar, targetVar);
|
script.copyStream(sourceVar, targetVar);
|
||||||
script.put();
|
script.put();
|
||||||
|
|||||||
Reference in New Issue
Block a user