feat(oracle): add dblink completion, tree view and management

This commit is contained in:
zipg authored and GitHub committed 2026-09-13 02:00:09 +08:00
1 parent 6694e4382e
commit b8f39f9c24
25 files changed
+645 -13

No files matched your search

@@ -647,7 +647,15 @@ describe("connectionStore metadata loading", () => {
const listTables = vi.fn().mockResolvedValue([{ name: "sheet", table_type: "TABLE", comment: null }]);
vi.doMock("@/lib/backend/tauriRuntime", () => ({ isTauriRuntime: () => false }));
const executeQuery = vi.fn().mockResolvedValue({
columns: ["OWNER", "DB_LINK", "USERNAME", "HOST", "CREATED"],
rows: [
["DBX_TEST", "PRIVATE.EXAMPLE", "REMOTE", "service", ""],
["PUBLIC", "PUBLIC.EXAMPLE", "REMOTE", "service", ""],
],
});
vi.doMock("@/lib/backend/api", () => ({
executeQuery,
checkConnectionHealth: vi.fn().mockResolvedValue(undefined),
deleteSchemaCachePrefix: vi.fn().mockResolvedValue(undefined),
listDatabases,
@@ -674,7 +682,23 @@ describe("connectionStore metadata loading", () => {
expect(listDatabases).not.toHaveBeenCalled();
expect(listSchemas).toHaveBeenCalledWith(connection.id, "");
expect(connectionNode.children?.map((node) => [node.type, node.label, node.database, node.schema])).toEqual([["schema", "DBX_TEST", "DBX_TEST", "DBX_TEST"]]);
expect(connectionNode.children?.map((node) => [node.type, node.label, node.database, node.schema])).toEqual([
["schema", "DBX_TEST", "DBX_TEST", "DBX_TEST"],
["oracle-db-links", "tree.databaseLinks", "", undefined],
]);
const linkRoot = connectionNode.children!.find((node) => node.type === "oracle-db-links")!;
await store.loadTreeNodeChildren(linkRoot, { force: true });
expect(executeQuery).toHaveBeenCalledWith(connection.id, "", expect.stringContaining("SESSION_USER"), undefined, undefined, { maxRows: 10000, timeoutSecs: 15 });
expect(linkRoot.children?.map((node) => [node.type, node.label, node.schema])).toEqual([
["oracle-db-link", "PRIVATE.EXAMPLE", "DBX_TEST"],
["oracle-db-link", "PUBLIC.EXAMPLE", "PUBLIC"],
]);
expect(linkRoot.objectCount).toBe(2);
executeQuery.mockResolvedValue({ columns: ["OWNER", "DB_LINK"], rows: [] });
await store.refreshOracleDatabaseLinks(connection.id);
expect(linkRoot.children).toEqual([]);
expect(linkRoot.objectCount).toBe(0);
const schemaNode = connectionNode.children?.[0];
expect(schemaNode).toBeDefined();
+50 -2
View File
@@ -80,6 +80,7 @@ import type { SqlCompletionColumn, SqlCompletionForeignKey, SqlCompletionObject,
import { usesOracleCurrentSchemaCompletion } from "@/lib/sql/oracleCompletionSession";
import { mergeSqlObjectNavigationType, sqlObjectNavigationTypeFromTableType } from "@/lib/sql/sqlNavigation";
import * as api from "@/lib/backend/api";
import { ORACLE_DATABASE_LINKS_SQL, oracleDatabaseLinksFromResult } from "@/lib/database/oracleDatabaseLinks";
import { isTauriRuntime } from "@/lib/backend/tauriRuntime";
import { useTunnelProfileStore } from "@/stores/tunnelProfileStore";
import { connectionIsDorisFamilyCatalogCapable, isInternalDorisCatalog, isSchemaAware, normalizeSidebarObjectKind, schemaNodeHasLoadableName, shouldShowDorisCatalogTree, sidebarObjectKindsForDatabase, supportsPackageMemberExpansion, usesTreeSchemaMode } from "@/lib/database/databaseCapabilities";
@@ -1505,7 +1506,7 @@ export const useConnectionStore = defineStore("connection", () => {
// as metadata children, withConnectionUtilityNodes would keep the old copies
// AND append fresh ones on every useCachedChildren pass, duplicating the
// 用户/角色 menus once per refresh cycle.
return node.type === "user-admin" || node.type === "dameng-users" || node.type === "dameng-roles" || node.type === "dameng-job-admin" || node.type === "group-tablespaces" || node.type === "saved-sql-root";
return node.type === "oracle-db-links" || node.type === "user-admin" || node.type === "dameng-users" || node.type === "dameng-roles" || node.type === "dameng-job-admin" || node.type === "group-tablespaces" || node.type === "saved-sql-root";
}
function connectionMetadataChildren(children: TreeNode[] | undefined): TreeNode[] {
@@ -1818,6 +1819,49 @@ export const useConnectionStore = defineStore("connection", () => {
};
}
function buildOracleDatabaseLinksNode(connectionId: string, existingConnectionNode?: TreeNode): TreeNode | undefined {
const config = getConfig(connectionId);
if (effectiveDatabaseTypeForConnection(config) !== "oracle") return undefined;
const existing = existingConnectionNode?.children?.find((child) => child.type === "oracle-db-links");
return { ...existing, id: `${connectionId}:__oracle_db_links`, label: "tree.databaseLinks", type: "oracle-db-links", connectionId, database: config?.database || "", isExpanded: existing?.isExpanded ?? false, children: existing?.children ?? [] };
}
async function listOracleDatabaseLinks(connectionId: string, database: string) {
if (effectiveDatabaseTypeForConnection(getConfig(connectionId)) !== "oracle") return [];
await ensureConnected(connectionId);
return oracleDatabaseLinksFromResult(await api.executeQuery(connectionId, database, ORACLE_DATABASE_LINKS_SQL, undefined, undefined, { maxRows: 10000, timeoutSecs: 15 }));
}
async function refreshOracleDatabaseLinks(connectionId: string) {
const root = findNode(treeNodes.value, `${connectionId}:__oracle_db_links`);
if (root) await loadOracleDatabaseLinks(root, { force: true });
}
async function loadOracleDatabaseLinks(node: TreeNode, options?: LoadTreeOptions) {
if (!node.connectionId) return;
await runConnectionTreeMetadataLoad(node.connectionId, node, async (load) => {
if (useCachedChildren(node, options, load)) return;
const links = await listOracleDatabaseLinks(node.connectionId!, node.database || "");
const target = treeNodeLoadTarget(load);
if (!target) return;
setChildren(
target,
links.map((link) => ({
id: `${node.id}:${encodeURIComponent(link.owner)}:${encodeURIComponent(link.name)}`,
label: link.name,
type: "oracle-db-link" as const,
connectionId: node.connectionId,
database: node.database,
schema: link.owner,
comment: `${link.owner} · ${link.username} · ${link.host}`,
isExpanded: false,
})),
);
target.objectCount = links.length;
target.isExpanded = true;
});
}
function withConnectionUtilityNodes(connectionId: string, children: TreeNode[], existingConnectionNode?: TreeNode): TreeNode[] {
const nonUtilityChildren = connectionMetadataChildren(children);
const userAdminNode = buildUserAdminNode(connectionId, existingConnectionNode);
@@ -1825,7 +1869,7 @@ export const useConnectionStore = defineStore("connection", () => {
const damengRoleNode = buildDamengRoleNode(connectionId, existingConnectionNode);
const damengJobAdminNode = buildDamengJobAdminNode(connectionId, existingConnectionNode);
const xuguTablespacesNode = buildXuguTablespacesNode(connectionId, existingConnectionNode);
return [...nonUtilityChildren, userAdminNode, damengUserNode, damengRoleNode, damengJobAdminNode, xuguTablespacesNode].filter(Boolean) as TreeNode[];
return [...nonUtilityChildren, buildOracleDatabaseLinksNode(connectionId, existingConnectionNode), userAdminNode, damengUserNode, damengRoleNode, damengJobAdminNode, xuguTablespacesNode].filter(Boolean) as TreeNode[];
}
function withSavedSqlRoot(connectionId: string, children: TreeNode[], existingConnectionNode?: TreeNode): TreeNode[] {
@@ -6743,6 +6787,8 @@ export const useConnectionStore = defineStore("connection", () => {
} else {
await loadDatabases(node.connectionId, options);
}
} else if (node.type === "oracle-db-links") {
await loadOracleDatabaseLinks(node, options);
} else if (node.type === "mongo-db" && node.connectionId && node.database) {
await loadMongoCollections(node.connectionId, node.database);
} else if (node.type === "vector-database" && node.connectionId && node.database) {
@@ -9103,6 +9149,8 @@ export const useConnectionStore = defineStore("connection", () => {
loadMoreObjectGroupChildren,
loadAllObjectGroupChildren,
loadTableGroups,
listOracleDatabaseLinks,
refreshOracleDatabaseLinks,
loadTreeNodeChildren,
loadColumns,
loadIndexes,