file format refactor

This commit is contained in:
Jan Prochazka
2020-11-19 08:36:56 +01:00
parent 64362cdf13
commit 6324fd1de4
7 changed files with 82 additions and 34 deletions

View File

@@ -1,7 +1,13 @@
export default {
import fileFormatBase from './fileFormatBase';
import { FileFormatDefinition } from './types';
const csvFormat: FileFormatDefinition = {
...fileFormatBase,
storageType: 'csv',
extension: 'csv',
name: 'CSV files',
name: 'CSV',
readerFunc: 'csvReader',
writerFunc: 'csvWriter',
};
export default csvFormat;

View File

@@ -1,6 +1,27 @@
export default {
import { DatabaseInfo } from 'dbgate-types';
import axios from '../utility/axios';
import fileFormatBase from './fileFormatBase';
import { FileFormatDefinition } from './types';
const excelFormat: FileFormatDefinition = {
...fileFormatBase,
storageType: 'excel',
extension: 'xlsx',
name: 'MS Excel files',
name: 'MS Excel',
readerFunc: 'excelSheetReader',
addFilesToSourceList: async (file, newSources, newValues) => {
const resp = await axios.get(`files/analyse-excel?filePath=${encodeURIComponent(file.full)}`);
const structure: DatabaseInfo = resp.data;
for (const table of structure.tables) {
const sourceName = table.pureName;
newSources.push(sourceName);
newValues[`sourceFile_${sourceName}`] = {
fileName: file.full,
sheetName: table.pureName,
};
}
},
};
export default excelFormat;

View File

@@ -0,0 +1,11 @@
const fileFormatBase = {
addFilesToSourceList: async (file, newSources, newValues) => {
const sourceName = file.name;
newSources.push(sourceName);
newValues[`sourceFile_${sourceName}`] = {
fileName: file.full,
};
},
};
export default fileFormatBase;

View File

@@ -1,7 +1,13 @@
export default {
import fileFormatBase from './fileFormatBase';
import { FileFormatDefinition } from './types';
const jsonlFormat: FileFormatDefinition = {
...fileFormatBase,
storageType: 'jsonl',
extension: 'jsonl',
name: 'JSON lines',
readerFunc: 'jsonLinesReader',
writerFunc: 'jsonLinesWriter',
};
export default jsonlFormat;

View File

@@ -4,4 +4,13 @@ export interface FileFormatDefinition {
name: string;
readerFunc?: string;
writerFunc?: string;
addFilesToSourceList: (
file: {
full: string;
},
newSources: string[],
newValues: {
[key: string]: any;
}
) => void;
}