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。
TypeScript aicliclickhousedatabasedatabase-clientdatabase-managementdockerguimcpmongodbmysqlpostgresqlredisrustsql-serversqlitetaurivue
fix(sundb): load tables by schema in the object tree
zipg7ca1b011ee32
diff --git a/agents/drivers/sundb/src/test/java/com/dbx/agent/sundb/SundbAgentMetadataTest.java b/agents/drivers/sundb/src/test/java/com/dbx/agent/sundb/SundbAgentMetadataTest.javaindex eb32dd430c..84fedcc519 100644--- a/agents/drivers/sundb/src/test/java/com/dbx/agent/sundb/SundbAgentMetadataTest.java+++ b/agents/drivers/sundb/src/test/java/com/dbx/agent/sundb/SundbAgentMetadataTest.java@@ -80,6 +80,35 @@ class SundbAgentMetadataTest {Assertions.assertTrue(statements.isEmpty(), "元数据不应执行手写 SQL: " + statements);}+ @Test+ void retriesSchemasWithoutTheCatalogFilterThatMatchesNoSunDbRows() {+ // 驱动的 getCatalog() 返回 null,所以 schema 查询会用连接上的 database 作为 catalog 过滤;+ // SUNDB 的 CATALOG_NAME 与该值不一致时会返回空集,此时必须退回不带 catalog 的 getSchemas(),+ // 否则对象树会停在空的 schema 节点上(库下的表永远加载不出来)。+ List<String> statements = new ArrayList<>();+ List<String> metadataRequests = new ArrayList<>();+ SundbAgent agent = new SundbAgent();+ DatabaseMetaData metadata = proxy(DatabaseMetaData.class, (proxy, method, args) -> {+ switch (method.getName()) {+ case "getCatalogs":+ return emptyRows();+ case "getSchemas":+ metadataRequests.add("getSchemas:" + args[0]);+ return args[0] == null ? schemas("APP", "PUBLIC") : emptyRows();+ default:+ return defaultValue(method.getReturnType());+ }+ });+ TestSupport.setPrivateConnection(agent, connection(statements, metadata));+ setConfiguredDatabase(agent, "SUNDB");++ List<String> schemas = agent.listSchemas();++ Assertions.assertEquals(List.of("getSchemas:SUNDB", "getSchemas:null"), metadataRequests);+ Assertions.assertEquals(List.of("APP", "PUBLIC"), schemas);+ Assertions.assertTrue(statements.isEmpty(), "元数据不应执行手写 SQL: " + statements);+ }+@Testvoid switchesSchemaWithSetSchemaInsteadOfMysqlUse() {SundbAgent agent = new SundbAgent();diff --git a/apps/desktop/src/lib/__tests__/database/databaseFeatureSupport.spec.ts b/apps/desktop/src/lib/__tests__/database/databaseFeatureSupport.spec.tsindex caa99d980c..f0bddeaf94 100644--- a/apps/desktop/src/lib/__tests__/database/databaseFeatureSupport.spec.ts+++ b/apps/desktop/src/lib/__tests__/database/databaseFeatureSupport.spec.ts@@ -43,6 +43,17 @@ describe("schema awareness", () => {expect(usesTreeSchemaMode("spanner")).toBe(true);});+ it("keeps SunDB on a schema tree so the database name is never used as the schema", () => {+ // SUNDB reports a real schema level (its driver implements SET SCHEMA and+ // DatabaseMetaData.getSchemas()), while the database in the JDBC URL is a+ // catalog. Without both traits the sidebar expanded the database node with+ // loadTables(database, undefined) and the agent sent the catalog name as the+ // getTables schemaPattern; the driver matched `TABLE_SCHEMA LIKE '<catalog>'`+ // and the tree showed "表 0" (issue #11360).+ expect(isSchemaAware("sundb")).toBe(true);+ expect(usesTreeSchemaMode("sundb")).toBe(true);+ });+it("treats Cloud Spanner's blank schema as a loadable node name", () => {// The GoogleSQL default schema node carries "", so a truthiness check would render an// expandable node that never loads its tables. Other types keep the truthiness test, which isdiff --git a/apps/desktop/src/lib/__tests__/database/jdbcDialect.spec.ts b/apps/desktop/src/lib/__tests__/database/jdbcDialect.spec.tsindex b1dad6799f..2dbbcd6d4b 100644--- a/apps/desktop/src/lib/__tests__/database/jdbcDialect.spec.ts+++ b/apps/desktop/src/lib/__tests__/database/jdbcDialect.spec.ts@@ -550,6 +550,22 @@ describe("object tree node schema", () => {expect(metadataSchemaForConnection({ db_type: "sqlserver" }, "dbx_test")).toBe("dbo");});+ it("keeps the SunDB catalog name out of the metadata schema", () => {+ // SUNDB's database (the JDBC URL path segment) is a catalog, and the driver+ // matches getTables' schemaPattern with a literal `TABLE_SCHEMA LIKE '<name>'`.+ // Sending the catalog name as the schema matched no objects, so the sidebar+ // showed an empty "表 0" node (issue #11360). The schema tree now resolves the+ // real schema first; before one is picked the blank schema lets the backend+ // use the session default.+ const connection = { db_type: "sundb" as const };+ expect(connectionObjectTreeQuerySchema(connection, "vpnccw")).toBe("");+ expect(connectionObjectTreeNodeSchema(connection, "vpnccw")).toBeUndefined();+ expect(metadataSchemaForConnection(connection, "vpnccw")).toBe("");+ // A real schema still passes through unchanged.+ expect(connectionObjectTreeQuerySchema(connection, "vpnccw", "APP")).toBe("APP");+ expect(connectionObjectTreeNodeSchema(connection, "vpnccw", "APP")).toBe("APP");+ });+it("keeps the database-as-schema fallback for engines whose database is the schema", () => {// Oracle, Dameng and the Hive family address objects as schema.table with no// separate schema level in the tree, so the database name is the schema therediff --git a/apps/desktop/src/stores/__tests__/connectionStore.metadataLoading.spec.ts b/apps/desktop/src/stores/__tests__/connectionStore.metadataLoading.spec.tsindex 97cadf5528..ce9d22d03a 100644--- a/apps/desktop/src/stores/__tests__/connectionStore.metadataLoading.spec.ts+++ b/apps/desktop/src/stores/__tests__/connectionStore.metadataLoading.spec.ts@@ -91,6 +91,19 @@ function xuguConnection(): ConnectionConfig {} as ConnectionConfig;}+function sundbConnection(): ConnectionConfig {+ return {+ id: "sundb-1",+ name: "SUNDB",+ db_type: "sundb",+ host: "10.156.156.86",+ port: 22581,+ username: "app_user",+ password: "",+ database: "vpnccw",+ } as ConnectionConfig;+}+function genericJdbcConnection(): ConnectionConfig {return {id: "jdbc-1",@@ -643,6 +656,51 @@ describe("connectionStore metadata loading", () => {]);});+ it("loads SunDB tables under the discovered schema instead of the catalog name", async () => {+ // SUNDB's database is a catalog, and the driver matches getTables' schemaPattern+ // literally, so sending the catalog name returned zero rows and the sidebar showed+ // an empty "表 0" node (issue #11360). The database node must discover schemas and+ // every table request must carry that schema.+ const listSchemaInfos = vi.fn().mockResolvedValue([{ name: "APP", comment: null }]);+ const listTables = vi.fn().mockResolvedValue([{ name: "ITEMS", table_type: "TABLE", comment: null }]);+ const listObjects = vi.fn().mockResolvedValue([]);++ vi.doMock("@/lib/backend/tauriRuntime", () => ({ isTauriRuntime: () => false }));+ vi.doMock("@/lib/backend/api", () => ({+ checkConnectionHealth: vi.fn().mockResolvedValue(undefined),+ deleteSchemaCachePrefix: vi.fn().mockResolvedValue(undefined),+ listSchemaInfos,+ listTables,+ listObjects,+ loadSchemaCache: vi.fn().mockResolvedValue(null),+ saveSchemaCache: vi.fn().mockResolvedValue(undefined),+ saveConnections: vi.fn().mockResolvedValue(undefined),+ saveSidebarLayout: vi.fn().mockResolvedValue(undefined),+ }));++ const { useConnectionStore } = await import("@/stores/connectionStore");+ const { useSettingsStore } = await import("@/stores/settingsStore");+ useSettingsStore().editorSettings.sidebarObjectDisplay = "simple";+ const store = useConnectionStore();+ const connection = sundbConnection();+ const databaseNode: TreeNode = { id: "sundb-1:vpnccw", label: "vpnccw", type: "database", connectionId: connection.id, database: "vpnccw", isExpanded: false, children: [] };+ store.connections = [connection];+ store.connectedIds.add(connection.id);+ store.treeNodes = [{ id: connection.id, label: connection.name, type: "connection", connectionId: connection.id, isExpanded: true, children: [databaseNode] }];++ await store.loadTreeNodeChildren(databaseNode, { force: true });++ expect(listSchemaInfos).toHaveBeenCalledWith(connection.id, "vpnccw");+ expect(listTables).not.toHaveBeenCalled();+ const schemaNode = databaseNode.children!.find((node) => node.type === "schema")!;+ expect([schemaNode.label, schemaNode.schema]).toEqual(["APP", "APP"]);++ await store.loadTreeNodeChildren(schemaNode, { force: true });++ const firstTableRequest = listTables.mock.calls[0] as unknown[];+ expect(firstTableRequest.slice(0, 3)).toEqual([connection.id, "vpnccw", "APP"]);+ });+it.each(["simple", "grouped"] as const)("isolates discovered JDBC schemas, pages and cached objects in %s mode", async (mode) => {const schemas = ["APP", "OTHER", "app", "A_B", "AXB", "_SYS_EPM"];const rowsForSchema = (schema: string): TableInfo[] => [...Array.from({ length: 3 }, (_, index) => ({ name: `${schema}_table_${index}`, table_type: "TABLE", comment: null })), ...Array.from({ length: 3 }, (_, index) => ({ name: `${schema}_view_${index}`, table_type: "VIEW", comment: null }))];diff --git a/crates/dbx-core/assets/database-drivers.manifest.json b/crates/dbx-core/assets/database-drivers.manifest.jsonindex 8c8575f33c..f2c6a9ca88 100644--- a/crates/dbx-core/assets/database-drivers.manifest.json+++ b/crates/dbx-core/assets/database-drivers.manifest.json@@ -2417,6 +2417,10 @@"metadataConnectionScoped": false,"skipTcpProbe": true,"defaultPort": 22581,+ "traits": {+ "schemaAware": true,+ "treeSchema": true+ },"supportLevel": "operate","capabilities": {"queryExecution": true,diff --git a/plugins/connection-types/sundb.yaml b/plugins/connection-types/sundb.yamlindex 8b4968fcd2..7f45d0221c 100644--- a/plugins/connection-types/sundb.yaml+++ b/plugins/connection-types/sundb.yaml@@ -13,6 +13,9 @@ singleConnectionPool: falsemetadataConnectionScoped: falseskipTcpProbe: truedefaultPort: 22581+traits:+ schemaAware: true+ treeSchema: truesupportLevel: operatecapabilities:queryExecution: true