Skip to content

armgit / dbx

Public Imported from GitHub
0

25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。

fix(structure): reuse compatible data type options

t8y255cad0cc0867
diff --git a/apps/desktop/src/components/structure/TableStructureEditor.vue b/apps/desktop/src/components/structure/TableStructureEditor.vue
index a3c914920a..6c9c1d4bb3 100644
--- a/apps/desktop/src/components/structure/TableStructureEditor.vue
+++ b/apps/desktop/src/components/structure/TableStructureEditor.vue
@@ -43,7 +43,7 @@ import {
combineDataTypeForDatabase,
createColumnDrafts,
createIndexDrafts,
- DATA_TYPE_OPTIONS,
+ getDataTypeOptions,
getDefaultLengthForType,
splitDataType,
toColumnNames,
@@ -137,7 +137,7 @@ const connection = computed(() => (props.connectionId ? store.getConfig(props.co
const databaseType = computed(() => connection.value?.db_type);
const structureCapabilities = computed(() => getTableStructureCapabilities(databaseType.value));
const isTableCommentDisabled = computed(() => !structureCapabilities.value.comment);
-const dataTypeOptions = computed(() => DATA_TYPE_OPTIONS[databaseType.value ?? ""] ?? []);
+const dataTypeOptions = computed(() => getDataTypeOptions(databaseType.value));
const indexTypesByDb: Record<string, string[]> = {
postgres: ["BTREE", "HASH", "GIST", "SPGIST", "GIN", "BRIN"],
diff --git a/apps/desktop/src/lib/tableStructureEditorState.ts b/apps/desktop/src/lib/tableStructureEditorState.ts
index 236dd7ec2c..85c68e2b08 100644
--- a/apps/desktop/src/lib/tableStructureEditorState.ts
+++ b/apps/desktop/src/lib/tableStructureEditorState.ts
@@ -230,6 +230,27 @@ export const DATA_TYPE_OPTIONS: Record<string, string[]> = {
],
};
+const DATA_TYPE_OPTION_ALIASES: Partial<Record<DatabaseType, string>> = {
+ doris: "mysql",
+ starrocks: "mysql",
+ goldendb: "mysql",
+ sundb: "mysql",
+ gaussdb: "postgres",
+ opengauss: "postgres",
+ redshift: "postgres",
+ highgo: "postgres",
+ vastbase: "postgres",
+ kingbase: "postgres",
+ dameng: "oracle",
+ "oceanbase-oracle": "oracle",
+ iris: "oracle",
+};
+
+export function getDataTypeOptions(dbType: DatabaseType | undefined): string[] {
+ const key = dbType ? (DATA_TYPE_OPTION_ALIASES[dbType] ?? dbType) : "";
+ return DATA_TYPE_OPTIONS[key] ?? [];
+}
+
export const DEFAULT_TYPE_LENGTHS: Record<string, string> = {
tinyint: "4",
smallint: "6",
diff --git a/packages/app-tests/tableStructureEditorState.test.ts b/packages/app-tests/tableStructureEditorState.test.ts
index 8a45b1009b..324e0f2c28 100644
--- a/packages/app-tests/tableStructureEditorState.test.ts
+++ b/packages/app-tests/tableStructureEditorState.test.ts
@@ -5,6 +5,7 @@ import {
combineDataTypeForDatabase,
createColumnDrafts,
createIndexDrafts,
+ getDataTypeOptions,
normalizeDataTypeParams,
parseExtraToColumnExtra,
toColumnNames,
@@ -159,3 +160,11 @@ test("normalizes temporal precision when combining data types", () => {
assert.equal(normalizeDataTypeParams("oracle", "timestamp", "9"), "9");
assert.equal(normalizeDataTypeParams("oracle", "timestamp", "10"), "");
});
+
+test("returns data type options for compatible table structure editors", () => {
+ assert.deepEqual(getDataTypeOptions("dameng"), getDataTypeOptions("oracle"));
+ assert.deepEqual(getDataTypeOptions("gaussdb"), getDataTypeOptions("postgres"));
+ assert.deepEqual(getDataTypeOptions("doris"), getDataTypeOptions("mysql"));
+ assert.equal(getDataTypeOptions("dameng").includes("varchar2"), true);
+ assert.equal(getDataTypeOptions("sqlserver").includes("nvarchar"), true);
+});