From df4d5904408e7e17bab63a7e523199266f16bc1a Mon Sep 17 00:00:00 2001 From: t8y2 <1156263951@qq.com> Date: Tue, 9 Jun 2026 13:20:29 +0800 Subject: [PATCH] fix(navicat): improve NCX connection type detection with numeric codes and port fallback MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add Navicat numeric ConnType codes (1-9) to typeMap for correct DB type mapping - Add port-based inference fallback (6379→Redis, 27017→MongoDB, etc.) - Expand typeMap with ClickHouse, Snowflake, KingbaseES, GaussDB, OceanBase - Skip unrecognized connections instead of silently falling back to MySQL --- apps/desktop/src/lib/navicatImport.ts | 44 +++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 6 deletions(-) diff --git a/apps/desktop/src/lib/navicatImport.ts b/apps/desktop/src/lib/navicatImport.ts index a090109040..399732f973 100644 --- a/apps/desktop/src/lib/navicatImport.ts +++ b/apps/desktop/src/lib/navicatImport.ts @@ -9,6 +9,7 @@ type ParsedNode = { }; const typeMap: Record = { + // String type identifiers (from Navicat ConnType / DatabaseType attributes) mysql: { dbType: "mysql", profile: "mysql", label: "MySQL", port: 3306, user: "root" }, mariadb: { dbType: "mysql", profile: "mariadb", label: "MariaDB", port: 3306, user: "root" }, postgresql: { dbType: "postgres", profile: "postgres", label: "PostgreSQL", port: 5432, user: "postgres" }, @@ -22,6 +23,21 @@ const typeMap: Record { const rawType = getAny(node.values, ["type", "connType", "connectionType", "databaseType", "driver", "dbType"]); - const profile = inferProfile(rawType, node.tag); - if (!profile) return null; + const portValue = Number(getAny(node.values, ["port", "serverPort"])); + const port = Number.isFinite(portValue) && portValue > 0 ? portValue : undefined; + const profile = inferProfile(rawType, node.tag, port); + if (!profile) { + const name = getAny(node.values, ["name", "connectionName", "connName", "caption", "title"]) || "(unnamed)"; + console.warn( + `[Navicat Import] 跳过无法识别类型的连接: "${name}" (type="${rawType}", tag="${node.tag}", port=${port ?? "N/A"})`, + ); + return null; + } const name = getAny(node.values, ["name", "connectionName", "connName", "caption", "title"]) || @@ -132,7 +165,6 @@ async function parseConnection(node: ParsedNode): Promise 0 ? portValue : profile.port, + port: port || profile.port, username, password, database: database || undefined,