mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-25 21:15:59 +00:00
file formats refactor
This commit is contained in:
7
packages/web/src/fileformats/csv.ts
Normal file
7
packages/web/src/fileformats/csv.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
export default {
|
||||
storageType: 'csv',
|
||||
extension: 'csv',
|
||||
readerFunc: 'csvReader',
|
||||
writerFunc: 'csvWriter',
|
||||
filesTitle: 'CSV files',
|
||||
};
|
||||
6
packages/web/src/fileformats/excel.ts
Normal file
6
packages/web/src/fileformats/excel.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
export default {
|
||||
storageType: 'excel',
|
||||
extension: 'xlsx',
|
||||
readerFunc: 'excelSheetReader',
|
||||
filesTitle: 'MS Excel files',
|
||||
};
|
||||
20
packages/web/src/fileformats/index.ts
Normal file
20
packages/web/src/fileformats/index.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import csv from './csv';
|
||||
import jsonl from './jsonl';
|
||||
import excel from './excel';
|
||||
import { FileFormatDefinition } from './types';
|
||||
|
||||
export const fileformats = [csv, jsonl, excel];
|
||||
|
||||
export function findFileFormat(storageType): FileFormatDefinition {
|
||||
return fileformats.find((x) => x.storageType == storageType);
|
||||
}
|
||||
|
||||
export function getFileFormatDirections(format: FileFormatDefinition) {
|
||||
if (!format) return [];
|
||||
const res = [];
|
||||
if (format.readerFunc) res.push('source');
|
||||
if (format.writerFunc) res.push('target');
|
||||
return res;
|
||||
}
|
||||
|
||||
export const defaultFileFormat = csv;
|
||||
7
packages/web/src/fileformats/jsonl.ts
Normal file
7
packages/web/src/fileformats/jsonl.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
export default {
|
||||
storageType: 'jsonl',
|
||||
extension: 'jsonl',
|
||||
readerFunc: 'jsonLinesReader',
|
||||
writerFunc: 'jsonLinesWriter',
|
||||
filesTitle: 'JSON lines',
|
||||
};
|
||||
7
packages/web/src/fileformats/types.ts
Normal file
7
packages/web/src/fileformats/types.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
export interface FileFormatDefinition {
|
||||
storageType: string;
|
||||
extension: string;
|
||||
readerFunc?: string;
|
||||
writerFunc?: string;
|
||||
filesTitle: string;
|
||||
}
|
||||
Reference in New Issue
Block a user