mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-25 20:06:00 +00:00
file format refactor
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
11
packages/web/src/fileformats/fileFormatBase.ts
Normal file
11
packages/web/src/fileformats/fileFormatBase.ts
Normal 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;
|
||||
@@ -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;
|
||||
|
||||
@@ -4,4 +4,13 @@ export interface FileFormatDefinition {
|
||||
name: string;
|
||||
readerFunc?: string;
|
||||
writerFunc?: string;
|
||||
addFilesToSourceList: (
|
||||
file: {
|
||||
full: string;
|
||||
},
|
||||
newSources: string[],
|
||||
newValues: {
|
||||
[key: string]: any;
|
||||
}
|
||||
) => void;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user