export/import column map support

This commit is contained in:
Jan Prochazka
2022-03-13 14:02:09 +01:00
parent 750a37a27f
commit 34dae68a62
9 changed files with 202 additions and 12 deletions

View File

@@ -1,5 +1,7 @@
import { TableInfo } from 'dbgate-types';
import _cloneDeep from 'lodash/cloneDeep';
import _fromPairs from 'lodash/fromPairs';
import _get from 'lodash/get';
export function prepareTableForImport(table: TableInfo): TableInfo {
const res = _cloneDeep(table);
@@ -10,3 +12,12 @@ export function prepareTableForImport(table: TableInfo): TableInfo {
if (res.primaryKey) res.primaryKey.constraintName = null;
return res;
}
interface TransformColumnDefinition {
src: string;
dst: string;
}
export function transformRowUsingColumnMap(row, columns: TransformColumnDefinition[]) {
return _fromPairs(columns.map(col => [col.dst, _get(row, col.src)]));
}