mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-20 17:06:01 +00:00
configurable dictionary description
This commit is contained in:
@@ -1,26 +1,27 @@
|
||||
import { DictionaryDescription } from 'dbgate-datalib';
|
||||
import { TableInfo } from 'dbgate-types';
|
||||
import _ from 'lodash';
|
||||
import { getLocalStorage, setLocalStorage, removeLocalStorage } from './storageCache';
|
||||
|
||||
interface DictionaryDescription {
|
||||
expression: string;
|
||||
columns: string[];
|
||||
delimiter: string;
|
||||
function checkDescriptionColumns(columns: string[], table: TableInfo) {
|
||||
return columns.length > 0 && columns.every(x => table.columns.find(y => y.columnName == x));
|
||||
}
|
||||
|
||||
function checkDescription(desc: DictionaryDescription, table: TableInfo) {
|
||||
return desc.columns.length > 0 && desc.columns.every(x => table.columns.find(y => y.columnName == x));
|
||||
}
|
||||
|
||||
export function getDictionaryDescription(table: TableInfo, conid: string, database: string): DictionaryDescription {
|
||||
export function getDictionaryDescription(
|
||||
table: TableInfo,
|
||||
conid: string,
|
||||
database: string,
|
||||
skipCheckSaved: boolean = false
|
||||
): DictionaryDescription {
|
||||
const keySpecific = `dictionary_spec_${table.schemaName}||${table.pureName}||${conid}||${database}`;
|
||||
const keyCommon = `dictionary_spec_${table.schemaName}||${table.pureName}`;
|
||||
|
||||
const cachedSpecific = getLocalStorage(keySpecific);
|
||||
const cachedCommon = getLocalStorage(keyCommon);
|
||||
|
||||
if (cachedSpecific && checkDescription(cachedSpecific, table)) return cachedSpecific;
|
||||
if (cachedCommon && checkDescription(cachedCommon, table)) return cachedCommon;
|
||||
if (cachedSpecific && (skipCheckSaved || checkDescriptionColumns(cachedSpecific.columns, table)))
|
||||
return cachedSpecific;
|
||||
if (cachedCommon && (skipCheckSaved || checkDescriptionColumns(cachedCommon.columns, table))) return cachedCommon;
|
||||
|
||||
const descColumn = table.columns.find(x => x?.dataType?.toLowerCase()?.includes('char'));
|
||||
if (descColumn) {
|
||||
@@ -34,10 +35,16 @@ export function getDictionaryDescription(table: TableInfo, conid: string, databa
|
||||
return null;
|
||||
}
|
||||
|
||||
export function parseDelimitedColumnList(columns) {
|
||||
export function parseDelimitedColumnList(columns): string[] {
|
||||
return _.compact((columns || '').split(',').map(x => x.trim()));
|
||||
}
|
||||
|
||||
export function checkDescriptionExpression(expression: string, table: TableInfo) {
|
||||
if (!expression) return false;
|
||||
if (!table) return false;
|
||||
return checkDescriptionColumns(parseDelimitedColumnList(expression), table);
|
||||
}
|
||||
|
||||
export function changeDelimitedColumnList(columns, columnName, isChecked) {
|
||||
const parsed = parseDelimitedColumnList(columns);
|
||||
const includes = parsed.includes(columnName);
|
||||
|
||||
Reference in New Issue
Block a user