default checked columns

This commit is contained in:
Jan Prochazka
2022-07-28 20:35:39 +02:00
parent d23371f642
commit 513b2ba42f
2 changed files with 48 additions and 4 deletions

View File

@@ -0,0 +1,19 @@
import { DatabaseInfo, TableInfo } from 'dbgate-types';
export function getPerspectiveDefaultColumns(table: TableInfo, db: DatabaseInfo): string[] {
const columns = table.columns.map(x => x.columnName);
const predicates = [
x => x.toLowerCase() == 'name',
x => x.toLowerCase() == 'title',
x => x.toLowerCase().includes('name'),
x => x.toLowerCase().includes('title'),
x => x.dataType?.toLowerCase()?.includes('char'),
];
for (const predicate of predicates) {
const col = columns.find(predicate);
if (col) return [col];
}
return [columns[0]];
}