forked from OtterMind/Chat2DB
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.ts
More file actions
74 lines (72 loc) · 2.01 KB
/
Copy pathdatabase.ts
File metadata and controls
74 lines (72 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import { DatabaseTypeCode } from '@/constants/common';
import { IWorkspaceModelType } from '@/models/workspace';
import { Option } from '@/typings/common';
export function handleDatabaseAndSchema(databaseAndSchema: IWorkspaceModelType['state']['databaseAndSchema']) {
let newCascaderOptions: Option[] = [];
if (databaseAndSchema.databases) {
newCascaderOptions = (databaseAndSchema?.databases || []).map((t) => {
let schemasList: Option[] = [];
if (t.schemas) {
schemasList = t.schemas.map((t) => {
return {
value: t.name,
label: t.name,
type: 'schema',
isLeaf: true,
};
});
}
return {
value: t.name,
label: t.name,
type: 'database',
children: schemasList,
isLeaf: schemasList.length === 0,
};
});
} else if (databaseAndSchema?.schemas) {
newCascaderOptions = (databaseAndSchema?.schemas || []).map((t) => {
return {
value: t.name,
label: t.name,
type: 'schema',
isLeaf: true,
};
});
}
return newCascaderOptions;
}
/**
* 兼容处理数据库名称
* @param databaseName
* @param databaseType
* @returns
*/
export function compatibleDataBaseName(databaseName: string, databaseType: DatabaseTypeCode) {
//"" oracele sqlite postgrsql h2 dm
// ` MYSQL clickhouse MariaDB
// [ sqlserver
if (
[
DatabaseTypeCode.ORACLE,
DatabaseTypeCode.SQLITE,
DatabaseTypeCode.POSTGRESQL,
DatabaseTypeCode.H2,
DatabaseTypeCode.DB2,
DatabaseTypeCode.KINGBASE,
DatabaseTypeCode.DM,
].includes(databaseType)
) {
return `"${databaseName}"`;
} else if ([DatabaseTypeCode.SQLSERVER].includes(databaseType)) {
return `[${databaseName}]`;
} else if (
[DatabaseTypeCode.MYSQL, DatabaseTypeCode.CLICKHOUSE, DatabaseTypeCode.TIMEPLUS, DatabaseTypeCode.MARIADB].includes(
databaseType,
)
) {
return `\`${databaseName}\``;
} else {
return `${databaseName}`;
}
}