mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-28 08:26:29 +00:00
default columns processor
This commit is contained in:
@@ -50,6 +50,7 @@ export interface PerspectiveNodeConfig {
|
|||||||
designerId: string;
|
designerId: string;
|
||||||
schemaName?: string;
|
schemaName?: string;
|
||||||
pureName: string;
|
pureName: string;
|
||||||
|
defaultColumnsProcessed?: boolean;
|
||||||
|
|
||||||
alias?: string;
|
alias?: string;
|
||||||
|
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ import stableStringify from 'json-stable-stringify';
|
|||||||
import { getFilterType, parseFilter } from 'dbgate-filterparser';
|
import { getFilterType, parseFilter } from 'dbgate-filterparser';
|
||||||
import { FilterType } from 'dbgate-filterparser/lib/types';
|
import { FilterType } from 'dbgate-filterparser/lib/types';
|
||||||
import { Condition, Expression, Select } from 'dbgate-sqltree';
|
import { Condition, Expression, Select } from 'dbgate-sqltree';
|
||||||
import { getPerspectiveDefaultColumns } from './getPerspectiveDefaultColumns';
|
// import { getPerspectiveDefaultColumns } from './getPerspectiveDefaultColumns';
|
||||||
import uuidv1 from 'uuid/v1';
|
import uuidv1 from 'uuid/v1';
|
||||||
|
|
||||||
export interface PerspectiveDataLoadPropsWithNode {
|
export interface PerspectiveDataLoadPropsWithNode {
|
||||||
|
|||||||
@@ -1,33 +0,0 @@
|
|||||||
import { findForeignKeyForColumn } from 'dbgate-tools';
|
|
||||||
import { DatabaseInfo, TableInfo, ViewInfo } from 'dbgate-types';
|
|
||||||
|
|
||||||
export function getPerspectiveDefaultColumns(
|
|
||||||
table: TableInfo | ViewInfo,
|
|
||||||
db: DatabaseInfo,
|
|
||||||
circularColumns: string[]
|
|
||||||
): 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.toLowerCase().includes('subject'),
|
|
||||||
// x => x.toLowerCase().includes('text'),
|
|
||||||
// x => x.toLowerCase().includes('desc'),
|
|
||||||
x =>
|
|
||||||
table.columns
|
|
||||||
.find(y => y.columnName == x)
|
|
||||||
?.dataType?.toLowerCase()
|
|
||||||
?.includes('char'),
|
|
||||||
x => findForeignKeyForColumn(table as TableInfo, x)?.columns?.length == 1 && !circularColumns.includes(x),
|
|
||||||
x => findForeignKeyForColumn(table as TableInfo, x)?.columns?.length == 1,
|
|
||||||
];
|
|
||||||
|
|
||||||
for (const predicate of predicates) {
|
|
||||||
const col = columns.find(predicate);
|
|
||||||
if (col) return [col];
|
|
||||||
}
|
|
||||||
|
|
||||||
return [columns[0]];
|
|
||||||
}
|
|
||||||
@@ -18,3 +18,4 @@ export * from './PerspectiveDisplay';
|
|||||||
export * from './PerspectiveDataProvider';
|
export * from './PerspectiveDataProvider';
|
||||||
export * from './PerspectiveCache';
|
export * from './PerspectiveCache';
|
||||||
export * from './PerspectiveConfig';
|
export * from './PerspectiveConfig';
|
||||||
|
export * from './processPerspectiveDefaultColunns';
|
||||||
|
|||||||
71
packages/datalib/src/processPerspectiveDefaultColunns.ts
Normal file
71
packages/datalib/src/processPerspectiveDefaultColunns.ts
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
import { findForeignKeyForColumn } from 'dbgate-tools';
|
||||||
|
import { DatabaseInfo, TableInfo, ViewInfo } from 'dbgate-types';
|
||||||
|
import { MultipleDatabaseInfo, PerspectiveConfig } from './PerspectiveConfig';
|
||||||
|
|
||||||
|
function getPerspectiveDefaultColumns(
|
||||||
|
table: TableInfo | ViewInfo,
|
||||||
|
db: DatabaseInfo,
|
||||||
|
circularColumns: string[]
|
||||||
|
): 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.toLowerCase().includes('subject'),
|
||||||
|
// x => x.toLowerCase().includes('text'),
|
||||||
|
// x => x.toLowerCase().includes('desc'),
|
||||||
|
x =>
|
||||||
|
table.columns
|
||||||
|
.find(y => y.columnName == x)
|
||||||
|
?.dataType?.toLowerCase()
|
||||||
|
?.includes('char'),
|
||||||
|
x => findForeignKeyForColumn(table as TableInfo, x)?.columns?.length == 1 && !circularColumns.includes(x),
|
||||||
|
x => findForeignKeyForColumn(table as TableInfo, x)?.columns?.length == 1,
|
||||||
|
];
|
||||||
|
|
||||||
|
for (const predicate of predicates) {
|
||||||
|
const col = columns.find(predicate);
|
||||||
|
if (col) return [col];
|
||||||
|
}
|
||||||
|
|
||||||
|
return [columns[0]];
|
||||||
|
}
|
||||||
|
|
||||||
|
export function processPerspectiveDefaultColunns(
|
||||||
|
config: PerspectiveConfig,
|
||||||
|
dbInfos: MultipleDatabaseInfo,
|
||||||
|
conid: string,
|
||||||
|
database: string
|
||||||
|
) {
|
||||||
|
for (const node of config.nodes) {
|
||||||
|
if (node.defaultColumnsProcessed) continue;
|
||||||
|
|
||||||
|
const db = dbInfos?.[conid]?.[database];
|
||||||
|
if (!db) continue;
|
||||||
|
|
||||||
|
const table = db.tables.find(x => x.pureName == node.pureName && x.schemaName == node.schemaName);
|
||||||
|
const view = db.views.find(x => x.pureName == node.pureName && x.schemaName == node.schemaName);
|
||||||
|
|
||||||
|
if (table || view) {
|
||||||
|
const defaultColumns = getPerspectiveDefaultColumns(table || view, db, []);
|
||||||
|
const newConfig = {
|
||||||
|
...config,
|
||||||
|
nodes: config.nodes.map(n =>
|
||||||
|
n.designerId == node.designerId
|
||||||
|
? {
|
||||||
|
...n,
|
||||||
|
defaultColumnsProcessed: true,
|
||||||
|
checkedColumns: defaultColumns,
|
||||||
|
}
|
||||||
|
: n
|
||||||
|
),
|
||||||
|
};
|
||||||
|
|
||||||
|
return newConfig;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
@@ -36,6 +36,7 @@
|
|||||||
PerspectiveDataProvider,
|
PerspectiveDataProvider,
|
||||||
PerspectiveTableColumnNode,
|
PerspectiveTableColumnNode,
|
||||||
PerspectiveTableNode,
|
PerspectiveTableNode,
|
||||||
|
processPerspectiveDefaultColunns,
|
||||||
} from 'dbgate-datalib';
|
} from 'dbgate-datalib';
|
||||||
|
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
@@ -147,6 +148,13 @@
|
|||||||
config.rootDesignerId
|
config.rootDesignerId
|
||||||
)
|
)
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
|
$: {
|
||||||
|
const newConfig = processPerspectiveDefaultColunns(config, $dbInfos, conid, database);
|
||||||
|
if (newConfig) {
|
||||||
|
setConfig(() => newConfig);
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<HorizontalSplitter initialValue={getInitialManagerSize()} bind:size={managerSize}>
|
<HorizontalSplitter initialValue={getInitialManagerSize()} bind:size={managerSize}>
|
||||||
|
|||||||
Reference in New Issue
Block a user