diff --git a/apps/desktop/src/components/connection/ConnectionDialog.vue b/apps/desktop/src/components/connection/ConnectionDialog.vue index 6201cfb0f..9f8dbff2e 100644 --- a/apps/desktop/src/components/connection/ConnectionDialog.vue +++ b/apps/desktop/src/components/connection/ConnectionDialog.vue @@ -40,6 +40,7 @@ import { buildDraftVisibleDatabasesConnectionId, connectionCanChooseVisibleDatab import { canSaveVisibleDatabaseSelection, filterDatabaseNamesForConnection, isSystemDatabaseName, normalizeVisibleDatabaseSelection, buildDraftVisibleSchemasConnectionId, normalizeVisibleSchemaSelection } from "@/lib/visibleDatabases"; import { isSchemaAware } from "@/lib/databaseFeatureSupport"; import VisibleSchemasDialog from "@/components/sidebar/VisibleSchemasDialog.vue"; +import { oceanbaseModeConnectionPatch, oceanbaseSubModeFromConfig } from "@/lib/oceanbaseConnectionMode"; type DbOption = { value: string; label: string }; type DbCategory = { key: string; title: string; options: DbOption[] }; @@ -885,13 +886,15 @@ watch( if (config) { const legacyConfig = config as LegacyConnectionConfig; const profile = profileForConfig(config); + const oceanbaseMode = profile === "oceanbase" ? oceanbaseSubModeFromConfig(config) : "mysql"; + const oceanbasePatch = profile === "oceanbase" ? oceanbaseModeConnectionPatch(oceanbaseMode) : null; editingId.value = config.id; const profileConfig = driverProfiles[profile]; form.value = { name: config.name, - db_type: profileConfig?.type || config.db_type, - driver_profile: profile, - driver_label: config.driver_label || driverProfiles[profile]?.label || config.db_type, + db_type: oceanbasePatch?.db_type || profileConfig?.type || config.db_type, + driver_profile: oceanbasePatch?.driver_profile || profile, + driver_label: config.driver_label || oceanbasePatch?.driver_label || driverProfiles[profile]?.label || config.db_type, url_params: config.url_params || "", host: config.db_type === "h2" ? config.host || h2FilePathFromJdbcUrl(config.connection_string) : config.host, port: profile === "tdengine" && (config.port === 0 || config.port === 6030) ? 6041 : config.port, @@ -941,7 +944,7 @@ watch( selectedTransportLayerId.value = form.value.transport_layers?.[0]?.id || null; selectedType.value = profile; if (profile === "oceanbase") { - oceanbaseSubMode.value = config.driver_profile === "oceanbase-oracle" ? "oracle" : "mysql"; + oceanbaseSubMode.value = oceanbaseMode; } if (profile === "gbase8a" || profile === "gbase8s") { selectedType.value = "gbase"; @@ -1489,6 +1492,9 @@ function generateConnectionName(): string { function connectionConfigForSubmit(id: string): ConnectionConfig { const config = { ...form.value, id } as LegacyConnectionConfig; + if (selectedType.value === "oceanbase") { + Object.assign(config, oceanbaseModeConnectionPatch(oceanbaseSubMode.value)); + } if (!config.name?.trim()) { config.name = generateConnectionName(); } diff --git a/apps/desktop/src/lib/oceanbaseConnectionMode.ts b/apps/desktop/src/lib/oceanbaseConnectionMode.ts new file mode 100644 index 000000000..4b59665ed --- /dev/null +++ b/apps/desktop/src/lib/oceanbaseConnectionMode.ts @@ -0,0 +1,26 @@ +import type { ConnectionConfig, DatabaseType } from "@/types/database"; + +export type OceanbaseSubMode = "mysql" | "oracle"; + +export function oceanbaseSubModeFromConfig(config: Pick): OceanbaseSubMode { + return config.db_type === "oceanbase-oracle" || config.driver_profile === "oceanbase-oracle" ? "oracle" : "mysql"; +} + +export function oceanbaseModeConnectionPatch(mode: OceanbaseSubMode): { + db_type: DatabaseType; + driver_profile: string; + driver_label: string; +} { + if (mode === "oracle") { + return { + db_type: "oceanbase-oracle", + driver_profile: "oceanbase-oracle", + driver_label: "OceanBase Oracle Mode", + }; + } + return { + db_type: "mysql", + driver_profile: "oceanbase", + driver_label: "OceanBase", + }; +} diff --git a/packages/app-tests/oceanbaseConnectionMode.test.ts b/packages/app-tests/oceanbaseConnectionMode.test.ts new file mode 100644 index 000000000..bc4ce1b7c --- /dev/null +++ b/packages/app-tests/oceanbaseConnectionMode.test.ts @@ -0,0 +1,22 @@ +import { strict as assert } from "node:assert"; +import { test } from "vitest"; +import { oceanbaseModeConnectionPatch, oceanbaseSubModeFromConfig } from "../../apps/desktop/src/lib/oceanbaseConnectionMode.ts"; + +test("detects OceanBase Oracle mode from either database type or driver profile", () => { + assert.equal(oceanbaseSubModeFromConfig({ db_type: "mysql", driver_profile: "oceanbase-oracle" }), "oracle"); + assert.equal(oceanbaseSubModeFromConfig({ db_type: "oceanbase-oracle", driver_profile: "oceanbase" }), "oracle"); + assert.equal(oceanbaseSubModeFromConfig({ db_type: "mysql", driver_profile: "oceanbase" }), "mysql"); +}); + +test("builds submit config identity from the selected OceanBase mode", () => { + assert.deepEqual(oceanbaseModeConnectionPatch("oracle"), { + db_type: "oceanbase-oracle", + driver_profile: "oceanbase-oracle", + driver_label: "OceanBase Oracle Mode", + }); + assert.deepEqual(oceanbaseModeConnectionPatch("mysql"), { + db_type: "mysql", + driver_profile: "oceanbase", + driver_label: "OceanBase", + }); +});