mirror of
https://github.com/Syngnat/GoNavi.git
synced 2026-08-04 21:07:45 +08:00
🐛 fix(metadata): 修复 Oracle 字段元数据显示缺失
- Oracle 元数据查询为字段名、类型、默认值、注释等列补齐稳定别名 - 新增字段定义归一化工具,兼容 name/Name/COLUMN_NAME 等返回形态 - 修复 DataGrid、DataViewer、QueryEditor、TableDesigner 对字段元数据的读取 - 补充 Oracle 字段注释、表头元数据和主键定位回归测试
This commit is contained in:
31
frontend/src/utils/columnDefinition.test.ts
Normal file
31
frontend/src/utils/columnDefinition.test.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import {
|
||||
getColumnDefinitionComment,
|
||||
getColumnDefinitionKey,
|
||||
getColumnDefinitionName,
|
||||
getColumnDefinitionType,
|
||||
normalizeColumnDefinition,
|
||||
} from './columnDefinition';
|
||||
|
||||
describe('columnDefinition metadata normalization', () => {
|
||||
it('reads Go/Wails style column metadata fields', () => {
|
||||
const column = { Name: 'UPDATED_AT', Type: 'TIMESTAMP', Key: 'PRI', Comment: '更新时间' };
|
||||
|
||||
expect(getColumnDefinitionName(column)).toBe('UPDATED_AT');
|
||||
expect(getColumnDefinitionType(column)).toBe('TIMESTAMP');
|
||||
expect(getColumnDefinitionKey(column)).toBe('PRI');
|
||||
expect(getColumnDefinitionComment(column)).toBe('更新时间');
|
||||
});
|
||||
|
||||
it('reads Oracle dictionary style column metadata aliases', () => {
|
||||
const column = { COLUMN_NAME: 'UPDATED_AT', DATA_TYPE: 'TIMESTAMP', COLUMN_KEY: 'PRI', COMMENTS: '更新时间' };
|
||||
|
||||
expect(normalizeColumnDefinition(column)).toMatchObject({
|
||||
name: 'UPDATED_AT',
|
||||
type: 'TIMESTAMP',
|
||||
key: 'PRI',
|
||||
comment: '更新时间',
|
||||
});
|
||||
});
|
||||
});
|
||||
59
frontend/src/utils/columnDefinition.ts
Normal file
59
frontend/src/utils/columnDefinition.ts
Normal file
@@ -0,0 +1,59 @@
|
||||
import type { ColumnDefinition } from '../types';
|
||||
|
||||
const readStringProperty = (value: unknown, keys: string[]): string => {
|
||||
const source = value as Record<string, unknown> | null | undefined;
|
||||
if (!source || typeof source !== 'object') return '';
|
||||
|
||||
for (const key of keys) {
|
||||
const raw = source[key];
|
||||
if (raw !== undefined && raw !== null) {
|
||||
return String(raw).trim();
|
||||
}
|
||||
}
|
||||
|
||||
for (const [sourceKey, raw] of Object.entries(source)) {
|
||||
if (keys.some((key) => sourceKey.toLowerCase() === key.toLowerCase())) {
|
||||
return raw === undefined || raw === null ? '' : String(raw).trim();
|
||||
}
|
||||
}
|
||||
|
||||
return '';
|
||||
};
|
||||
|
||||
export const getColumnDefinitionName = (column: unknown): string => (
|
||||
readStringProperty(column, ['name', 'Name', 'COLUMN_NAME', 'column_name', 'field', 'Field'])
|
||||
);
|
||||
|
||||
export const getColumnDefinitionType = (column: unknown): string => (
|
||||
readStringProperty(column, ['type', 'Type', 'DATA_TYPE', 'data_type'])
|
||||
);
|
||||
|
||||
export const getColumnDefinitionKey = (column: unknown): string => (
|
||||
readStringProperty(column, ['key', 'Key', 'COLUMN_KEY', 'column_key'])
|
||||
);
|
||||
|
||||
export const getColumnDefinitionExtra = (column: unknown): string => (
|
||||
readStringProperty(column, ['extra', 'Extra'])
|
||||
);
|
||||
|
||||
export const getColumnDefinitionComment = (column: unknown): string => (
|
||||
readStringProperty(column, ['comment', 'Comment', 'COMMENTS', 'comments', 'COLUMN_COMMENT', 'column_comment'])
|
||||
);
|
||||
|
||||
export const normalizeColumnDefinition = (column: unknown): ColumnDefinition => {
|
||||
const source = (column && typeof column === 'object' ? column : {}) as Partial<ColumnDefinition>;
|
||||
return {
|
||||
...source,
|
||||
name: getColumnDefinitionName(column),
|
||||
type: getColumnDefinitionType(column),
|
||||
nullable: readStringProperty(column, ['nullable', 'Nullable', 'NULLABLE', 'is_nullable']),
|
||||
key: getColumnDefinitionKey(column),
|
||||
default: source.default,
|
||||
extra: getColumnDefinitionExtra(column),
|
||||
comment: getColumnDefinitionComment(column),
|
||||
};
|
||||
};
|
||||
|
||||
export const normalizeColumnDefinitions = (columns: unknown): ColumnDefinition[] => (
|
||||
Array.isArray(columns) ? columns.map(normalizeColumnDefinition) : []
|
||||
);
|
||||
Reference in New Issue
Block a user