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(xugu): preserve type members during refresh

Elias90af02619320
diff --git a/apps/desktop/src/stores/__tests__/connectionStore.metadataLoading.spec.ts b/apps/desktop/src/stores/__tests__/connectionStore.metadataLoading.spec.ts
index 5788a868ec..e049a5dd5e 100644
--- a/apps/desktop/src/stores/__tests__/connectionStore.metadataLoading.spec.ts
+++ b/apps/desktop/src/stores/__tests__/connectionStore.metadataLoading.spec.ts
@@ -188,7 +188,7 @@ describe("connectionStore metadata loading", () => {
database: "app_db",
schema: "app_schema",
children: [],
- isExpanded: false,
+ isExpanded: true,
};
store.connections = [connection];
store.connectedIds = new Set([connection.id]);
@@ -301,6 +301,48 @@ describe("connectionStore metadata loading", () => {
expect(typeNode.children?.every((child) => child.parentName === "ADDRESS_T")).toBe(true);
}, 15000);
+ it("keeps expanded Xugu type members loaded during forced tree refresh", async () => {
+ const completionAssistantSearch = vi.fn(async (request: { object_kinds?: string[] }) => ({
+ candidates: request.object_kinds?.includes("column") ? [{ name: "street", kind: "column", data_type: "VARCHAR(120)" }] : [],
+ incomplete: false,
+ fallback_used: false,
+ }));
+ const getCustomTypeDetails = vi.fn().mockRejectedValue(new Error("custom type loader must not be called for Xugu types"));
+ vi.doMock("@/lib/backend/tauriRuntime", () => ({ isTauriRuntime: () => false }));
+ vi.doMock("@/lib/backend/api", () => ({
+ checkConnectionHealth: vi.fn().mockResolvedValue(undefined),
+ completionAssistantSearch,
+ deleteSchemaCachePrefix: vi.fn().mockResolvedValue(undefined),
+ getCustomTypeDetails,
+ }));
+
+ const { useConnectionStore } = await import("@/stores/connectionStore");
+ const store = useConnectionStore();
+ const connection = xuguConnection();
+ const typeNode: TreeNode = {
+ id: "xugu-1:app_db:app_schema:type:address_t",
+ label: "ADDRESS_T",
+ type: "type",
+ objectName: "ADDRESS_T",
+ connectionId: connection.id,
+ database: "app_db",
+ schema: "app_schema",
+ xuguTypeMembersExpandable: true,
+ children: [],
+ isExpanded: false,
+ };
+ store.connections = [connection];
+ store.connectedIds = new Set([connection.id]);
+ store.treeNodes = [typeNode];
+
+ await store.refreshTreeNode(typeNode);
+
+ expect(getCustomTypeDetails).not.toHaveBeenCalled();
+ expect(completionAssistantSearch).toHaveBeenCalledTimes(2);
+ expect(typeNode.children?.map((child) => [child.type, child.objectCount])).toEqual([["type-attributes", 1]]);
+ expect(typeNode.isExpanded).toBe(true);
+ }, 15000);
+
it("hides the Xugu type expander after loading no members", async () => {
const completionAssistantSearch = vi.fn().mockResolvedValue({ candidates: [], incomplete: false, fallback_used: false });
vi.doMock("@/lib/backend/tauriRuntime", () => ({ isTauriRuntime: () => false }));
diff --git a/apps/desktop/src/stores/connectionStore.ts b/apps/desktop/src/stores/connectionStore.ts
index a1f5adac7c..078a581248 100644
--- a/apps/desktop/src/stores/connectionStore.ts
+++ b/apps/desktop/src/stores/connectionStore.ts
@@ -6119,6 +6119,11 @@ export const useConnectionStore = defineStore("connection", () => {
await loadTables(node.connectionId, node.database, node.schema, options);
} else if ((node.type === "table" || node.type === "view" || node.type === "materialized_view") && node.connectionId && hasTreeNodeDatabaseContext(node)) {
await loadTableGroups(node.connectionId, node.database, node.label, node.schema, node.id, node.catalog);
+ } else if (node.type === "type" && isXuguTypeMemberContainer(node, getConfig(node.connectionId || "")?.db_type)) {
+ // Xugu object types expose attributes and methods through the scoped
+ // completion endpoint. Do not route them through the generic custom-type
+ // loader, which treats the type name as a table and issues getColumns.
+ await loadXuguTypeMembers(node, options);
} else if (node.type === "type") {
await loadCustomTypeChildren(node, options);
} else if (node.type === "group-columns" && node.connectionId && hasTreeNodeDatabaseContext(node) && node.tableName) {
@@ -6447,17 +6452,17 @@ export const useConnectionStore = defineStore("connection", () => {
}
}
- async function loadXuguTypeMembers(node: TreeNode, options?: Pick<LoadTreeOptions, "preserveCollapsedChildren">): Promise<void> {
+ async function loadXuguTypeMembers(node: TreeNode, options?: Pick<LoadTreeOptions, "force" | "preserveCollapsedChildren">): Promise<void> {
if (!isXuguTypeMemberContainer(node, getConfig(node.connectionId || "")?.db_type)) return;
const connectionId = node.connectionId;
const database = node.database;
if (!connectionId || !database) return;
- if (node.isExpanded) {
+ if (node.isExpanded && !options?.force) {
node.isExpanded = false;
if (!sidebarSearchQuery.value && !options?.preserveCollapsedChildren) releaseCollapsedTreeNodeChildren(node.id);
return;
}
- if (node.children && node.children.length > 0) {
+ if (!options?.force && node.children && node.children.length > 0) {
node.isExpanded = true;
return;
}