mirror of
https://github.com/dbgate/dbgate
synced 2024-11-07 20:26:23 +00:00
import from archive
This commit is contained in:
parent
e833853d3f
commit
6792b652fb
11
packages/api/src/shell/archiveReader.js
Normal file
11
packages/api/src/shell/archiveReader.js
Normal file
@ -0,0 +1,11 @@
|
||||
const path = require('path');
|
||||
const { archivedir } = require('../utility/directories');
|
||||
const jsonLinesReader = require('./jsonLinesReader');
|
||||
|
||||
function archiveReader({ folderName, fileName }) {
|
||||
const jsonlFile = path.join(archivedir(), folderName, `${fileName}.jsonl`);
|
||||
const res = jsonLinesReader({ fileName: jsonlFile });
|
||||
return res;
|
||||
}
|
||||
|
||||
module.exports = archiveReader;
|
@ -12,6 +12,7 @@ const jsonLinesWriter = require('./jsonLinesWriter');
|
||||
const jsonLinesReader = require('./jsonLinesReader');
|
||||
const jslDataReader = require('./jslDataReader');
|
||||
const archiveWriter = require('./archiveWriter');
|
||||
const archiveReader = require('./archiveReader');
|
||||
|
||||
module.exports = {
|
||||
queryReader,
|
||||
@ -28,4 +29,5 @@ module.exports = {
|
||||
consoleObjectWriter,
|
||||
jslDataReader,
|
||||
archiveWriter,
|
||||
archiveReader,
|
||||
};
|
||||
|
@ -618,25 +618,26 @@ export default function DataGridCore(props) {
|
||||
}
|
||||
|
||||
function exportGrid() {
|
||||
showModal((modalState) => (
|
||||
<ImportExportModal
|
||||
modalState={modalState}
|
||||
initialValues={{
|
||||
// sourceStorageType: jslid ? 'jsldata' : 'database',
|
||||
// sourceJslId: jslid,
|
||||
// sourceConnectionId: jslid ? undefined : conid,
|
||||
// sourceDatabaseName: jslid ? undefined : database,
|
||||
// sourceSchemaName: jslid ? undefined : display.baseTable && display.baseTable.schemaName,
|
||||
// sourceList: jslid ? ['query-data'] : display.baseTable ? [display.baseTable.pureName] : [],
|
||||
sourceStorageType: jslid ? 'jsldata' : 'query',
|
||||
sourceJslId: jslid,
|
||||
sourceConnectionId: jslid ? undefined : conid,
|
||||
sourceDatabaseName: jslid ? undefined : database,
|
||||
sourceSql: display.getExportQuery(),
|
||||
sourceList: jslid ? ['query-data'] : display.baseTable ? [display.baseTable.pureName] : [],
|
||||
}}
|
||||
/>
|
||||
));
|
||||
const initialValues = {};
|
||||
if (jslid) {
|
||||
const archiveMatch = jslid.match(/^archive:\/\/([^/]+)\/(.*)$/);
|
||||
if (archiveMatch) {
|
||||
initialValues.sourceStorageType = 'archive';
|
||||
initialValues.sourceArchiveFolder = archiveMatch[1];
|
||||
initialValues.sourceList = [archiveMatch[2]];
|
||||
} else {
|
||||
initialValues.sourceStorageType = 'jsldata';
|
||||
initialValues.sourceJslId = jslid;
|
||||
initialValues.sourceList = ['query-data'];
|
||||
}
|
||||
} else {
|
||||
initialValues.sourceStorageType = 'query';
|
||||
initialValues.sourceConnectionId = conid;
|
||||
initialValues.sourceDatabaseName = database;
|
||||
initialValues.sourceSql = display.getExportQuery();
|
||||
initialValues.sourceList = display.baseTable ? [display.baseTable.pureName] : [];
|
||||
}
|
||||
showModal((modalState) => <ImportExportModal modalState={modalState} initialValues={initialValues} />);
|
||||
}
|
||||
|
||||
function setCellValue(chs, cell, value) {
|
||||
|
@ -10,8 +10,9 @@ import {
|
||||
FormTablesSelect,
|
||||
FormSchemaSelect,
|
||||
FormArchiveFolderSelect,
|
||||
FormArchiveFilesSelect,
|
||||
} from '../utility/forms';
|
||||
import { useConnectionInfo, useDatabaseInfo } from '../utility/metadataLoaders';
|
||||
import { useArchiveFiles, useConnectionInfo, useDatabaseInfo } from '../utility/metadataLoaders';
|
||||
import TableControl, { TableColumn } from '../utility/TableControl';
|
||||
import { TextField, SelectField } from '../utility/inputs';
|
||||
import { getActionOptions, getTargetName, isFileStorage } from './createImpExpScript';
|
||||
@ -167,6 +168,7 @@ function SourceTargetConfig({
|
||||
];
|
||||
const storageType = values[storageTypeField];
|
||||
const dbinfo = useDatabaseInfo({ conid: values[connectionIdField], database: values[databaseNameField] });
|
||||
const archiveFiles = useArchiveFiles({ folder: values[archiveFolderField] });
|
||||
return (
|
||||
<Column>
|
||||
{direction == 'source' && <Label>Source configuration</Label>}
|
||||
@ -241,6 +243,26 @@ function SourceTargetConfig({
|
||||
</>
|
||||
)}
|
||||
|
||||
{storageType == 'archive' && direction == 'source' && (
|
||||
<>
|
||||
<Label>Source files</Label>
|
||||
<FormArchiveFilesSelect folderName={values[archiveFolderField]} name={tablesField} />
|
||||
<div>
|
||||
<FormStyledButton
|
||||
type="button"
|
||||
value="All files"
|
||||
onClick={() =>
|
||||
setFieldValue(
|
||||
'sourceList',
|
||||
_.uniq([...(values.sourceList || []), ...(archiveFiles && archiveFiles.map((x) => x.name))])
|
||||
)
|
||||
}
|
||||
/>
|
||||
<FormStyledButton type="button" value="Remove all" onClick={() => setFieldValue('sourceList', [])} />
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
|
||||
{isFileStorage(storageType) && direction == 'source' && <FilesInput />}
|
||||
</Column>
|
||||
);
|
||||
|
@ -68,6 +68,15 @@ function getSourceExpr(sourceName, values, sourceConnection, sourceDriver) {
|
||||
if (sourceStorageType == 'jsldata') {
|
||||
return ['jslDataReader', { jslid: values.sourceJslId }];
|
||||
}
|
||||
if (sourceStorageType == 'archive') {
|
||||
return [
|
||||
'archiveReader',
|
||||
{
|
||||
folderName: values.sourceArchiveFolder,
|
||||
fileName: sourceName,
|
||||
},
|
||||
];
|
||||
}
|
||||
throw new Error(`Unknown source storage type: ${sourceStorageType}`);
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,13 @@ import Creatable from 'react-select/creatable';
|
||||
import { TextField, SelectField } from './inputs';
|
||||
import { Field, useFormikContext } from 'formik';
|
||||
import FormStyledButton from '../widgets/FormStyledButton';
|
||||
import { useConnectionList, useDatabaseList, useDatabaseInfo, useArchiveFolders } from './metadataLoaders';
|
||||
import {
|
||||
useConnectionList,
|
||||
useDatabaseList,
|
||||
useDatabaseInfo,
|
||||
useArchiveFolders,
|
||||
useArchiveFiles,
|
||||
} from './metadataLoaders';
|
||||
import useSocket from './SocketProvider';
|
||||
import getAsArray from './getAsArray';
|
||||
import axios from './axios';
|
||||
@ -174,6 +180,22 @@ export function FormTablesSelect({ conidName, databaseName, schemaName, name })
|
||||
return <FormReactSelect options={tablesOptions} name={name} isMulti />;
|
||||
}
|
||||
|
||||
export function FormArchiveFilesSelect({ folderName, name }) {
|
||||
// const { values } = useFormikContext();
|
||||
const files = useArchiveFiles({ folder: folderName });
|
||||
const filesOptions = React.useMemo(
|
||||
() =>
|
||||
(files || []).map((x) => ({
|
||||
value: x.name,
|
||||
label: x.name,
|
||||
})),
|
||||
[files]
|
||||
);
|
||||
|
||||
if (filesOptions.length == 0) return <div>Not available</div>;
|
||||
return <FormReactSelect options={filesOptions} name={name} isMulti />;
|
||||
}
|
||||
|
||||
export function FormArchiveFolderSelect({ name }) {
|
||||
const { setFieldValue } = useFormikContext();
|
||||
const folders = useArchiveFolders();
|
||||
|
Loading…
Reference in New Issue
Block a user