Files
dbgate/packages/tools/src/tableTransforms.ts
2022-03-13 14:02:09 +01:00

24 lines
655 B
TypeScript

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);
res.foreignKeys = [];
res.indexes = [];
res.uniques = [];
res.checks = [];
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)]));
}