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(jdbc): load schemas in database browser for oracle jdbc connections (#13646) (#13721)

lxk9556660325e722c
diff --git a/apps/desktop/src/components/objects/DatabaseBrowser.vue b/apps/desktop/src/components/objects/DatabaseBrowser.vue
index 54187d3ee6..3c575a3799 100644
--- a/apps/desktop/src/components/objects/DatabaseBrowser.vue
+++ b/apps/desktop/src/components/objects/DatabaseBrowser.vue
@@ -10,12 +10,13 @@ import ToolbarOverflowMenu from "@/components/ui/ToolbarOverflowMenu.vue";
import CustomContextMenu, { type ContextMenuItem } from "@/components/ui/CustomContextMenu.vue";
import { openSidebarDangerDialog } from "@/lib/sidebar/sidebarDangerDialog";
import { useDatabaseBrowserMutation } from "@/lib/database/databaseBrowserActions";
+import { connectionUsesConnectionRootSchemaMode } from "@/lib/database/jdbcDialect";
import { objectBrowserTargetForNamespaceRow } from "@/lib/database/objectBrowserTarget";
import SidebarTreeRuntimeHost from "@/components/sidebar/SidebarTreeRuntimeHost.vue";
import SidebarTreeItemDialogs from "@/components/sidebar/SidebarTreeItemDialogs.vue";
import { useToolbarOverflow } from "@/composables/useToolbarOverflow";
import * as api from "@/lib/backend/api";
-import { filterDatabaseNamesForConnection } from "@/lib/database/visibleDatabases";
+import { filterDatabaseNamesForConnection, filterSchemaNamesForConnection } from "@/lib/database/visibleDatabases";
import { formatObjectBrowserBytes, formatObjectBrowserTimestamp } from "@/lib/table/objectBrowserRows";
import { requestObjectBrowserSearchFocus } from "@/lib/tabs/objectBrowserSearchFocus";
import { useTabUiState } from "@/lib/tabs/tabUiState";
@@ -196,11 +197,11 @@ function databaseContextMenuItems(row: DatabaseRow): ContextMenuItem[] {
action: () => {
const dbType = props.connection.db_type;
const sql = dbType === "mysql" ? `SHOW CREATE DATABASE \`${row.name.replaceAll("`", "``")}\`;` : `-- ${row.name}\n-- Database DDL is not available for this driver.`;
- queryStore.createTab(props.connection.id, row.name, `${row.name} - ${t("contextMenu.viewDdl")}`, "query", undefined, sql, undefined, { forceNew: true });
+ queryStore.createTab(props.connection.id, target.database, `${row.name} - ${t("contextMenu.viewDdl")}`, "query", target.schema, sql, undefined, { forceNew: true });
},
icon: Copy,
},
- { sidebarActionId: "contextMenu.newQuery", label: t("contextMenu.newQuery"), action: () => queryStore.createTab(props.connection.id, row.name, `${row.name} - ${t("contextMenu.newQuery")}`, "query", undefined, undefined, undefined, { forceNew: true }), icon: TerminalSquare },
+ { sidebarActionId: "contextMenu.newQuery", label: t("contextMenu.newQuery"), action: () => queryStore.createTab(props.connection.id, target.database, `${row.name} - ${t("contextMenu.newQuery")}`, "query", target.schema, undefined, undefined, { forceNew: true }), icon: TerminalSquare },
{ sidebarActionId: "contextMenu.copyName", label: t("contextMenu.copyName"), action: () => copyToClipboard(row.name), icon: Copy },
{ label: "", separator: true },
{
@@ -403,7 +404,46 @@ async function refresh(): Promise<boolean> {
loading.value = true;
error.value = "";
try {
+ if (connectionUsesConnectionRootSchemaMode(props.connection)) {
+ const database = props.connection.database || "";
+ let schemas: Array<{ name: string; comment?: string | null }> = [];
+ try {
+ schemas = await api.listSchemaInfos(props.connection.id, database);
+ } catch {
+ const names = await api.listSchemas(props.connection.id, database, true).catch(() => []);
+ schemas = names.map((name) => ({ name, comment: null }));
+ }
+ if (generation !== refreshGeneration) return true;
+ if (schemas.length === 0) {
+ const databases = await api.listDatabases(props.connection.id).catch(() => []);
+ if (generation !== refreshGeneration) return true;
+ schemas = databases.map((database) => ({ name: database.name, comment: database.comment ?? null }));
+ }
+ const visibleNames = new Set(
+ filterSchemaNamesForConnection(
+ schemas.map((schema) => schema.name),
+ props.connection,
+ database,
+ ),
+ );
+ rows.value = schemas
+ .filter((schema) => schema.name.trim() && visibleNames.has(schema.name))
+ .map((schema) => ({
+ name: schema.name,
+ sizeBytes: null,
+ createdAt: null,
+ updatedAt: null,
+ comment: schema.comment ?? null,
+ defaultCharset: null,
+ defaultCollation: null,
+ }));
+ loading.value = false;
+ restoreScrollPosition();
+ return true;
+ }
+
const databases = await api.listDatabases(props.connection.id);
+ if (generation !== refreshGeneration) return true;
const visibleNames = new Set(
filterDatabaseNamesForConnection(
databases.map((database) => database.name),
diff --git a/apps/desktop/src/components/objects/__tests__/DatabaseBrowser.schemaMode.component.spec.ts b/apps/desktop/src/components/objects/__tests__/DatabaseBrowser.schemaMode.component.spec.ts
new file mode 100644
index 0000000000..f44b7fabb1
--- /dev/null
+++ b/apps/desktop/src/components/objects/__tests__/DatabaseBrowser.schemaMode.component.spec.ts
@@ -0,0 +1,268 @@
+// @vitest-environment happy-dom
+
+import { createApp, type App } from "vue";
+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
+import DatabaseBrowser from "../DatabaseBrowser.vue";
+import type { ConnectionConfig } from "@/types/database";
+
+const testSchemas = [
+ { name: "APP", comment: "Application Schema" },
+ { name: "HR", comment: null },
+ { name: "SALES", comment: "Sales Schema" },
+];
+
+const testDatabases = [{ name: "db_mysql", size_bytes: 1024, created_at: null, updated_at: null, comment: null, default_charset: "utf8mb4", default_collation: "utf8mb4_0900_ai_ci" }];
+
+const mocks = vi.hoisted(() => ({
+ listDatabases: vi.fn(),
+ listDatabaseMetadata: vi.fn(),
+ listSchemaInfos: vi.fn(),
+ listSchemas: vi.fn(),
+ openObjectBrowser: vi.fn(),
+ editorSettings: {
+ objectBrowserViewMode: "list" as "list" | "grid" | "compact",
+ objectBrowserCompactWidth: 160,
+ },
+}));
+
+vi.mock("@/lib/backend/api", () => ({
+ listDatabases: (...args: unknown[]) => mocks.listDatabases(...args),
+ listDatabaseMetadata: (...args: unknown[]) => mocks.listDatabaseMetadata(...args),
+ listSchemaInfos: (...args: unknown[]) => mocks.listSchemaInfos(...args),
+ listSchemas: (...args: unknown[]) => mocks.listSchemas(...args),
+}));
+
+vi.mock("@/stores/connectionStore", () => ({
+ useConnectionStore: () => ({
+ setDefaultDatabase: vi.fn(),
+ clearDefaultDatabase: vi.fn(),
+ }),
+}));
+
+vi.mock("@/stores/queryStore", () => ({
+ useQueryStore: () => ({
+ openObjectBrowser: (...args: unknown[]) => mocks.openObjectBrowser(...args),
+ createTab: vi.fn(),
+ }),
+}));
+
+vi.mock("@/stores/settingsStore", () => ({
+ useSettingsStore: () => ({
+ editorSettings: mocks.editorSettings,
+ updateEditorSettings: (patch: Partial<typeof mocks.editorSettings>) => {
+ Object.assign(mocks.editorSettings, patch);
+ },
+ }),
+}));
+
+vi.mock("vue-i18n", () => ({
+ useI18n: () => ({
+ t: (key: string) => key,
+ locale: { value: "en-US" },
+ }),
+}));
+
+vi.mock("@/components/sidebar/SidebarTreeRuntimeHost.vue", () => ({
+ default: {
+ setup() {
+ return () => null;
+ },
+ },
+}));
+
+vi.mock("@/components/sidebar/SidebarTreeItemDialogs.vue", () => ({
+ default: {
+ setup() {
+ return () => null;
+ },
+ },
+}));
+
+vi.mock("@/composables/useToolbarOverflow", () => ({
+ useToolbarOverflow: () => ({
+ tier: { value: 0 },
+ }),
+}));
+
+describe("DatabaseBrowser connection-root schema mode (#13646)", () => {
+ let app: App | undefined;
+ let host: HTMLElement | undefined;
+
+ beforeEach(() => {
+ mocks.listDatabases.mockResolvedValue(testDatabases);
+ mocks.listDatabaseMetadata.mockResolvedValue([]);
+ mocks.listSchemaInfos.mockResolvedValue(testSchemas);
+ mocks.listSchemas.mockResolvedValue(testSchemas.map((s) => s.name));
+ mocks.openObjectBrowser.mockReturnValue("tab-1");
+ });
+
+ afterEach(() => {
+ app?.unmount();
+ host?.remove();
+ app = undefined;
+ host = undefined;
+ vi.clearAllMocks();
+ });
+
+ it("loads and displays schemas for Oracle JDBC connection (#13646)", async () => {
+ const oracleJdbcConnection: ConnectionConfig = {
+ id: "conn-oracle-jdbc",
+ name: "Oracle 11g JDBC",
+ db_type: "jdbc",
+ connection_string: "jdbc:oracle:thin:@127.0.0.1:1521:xe",
+ };
+
+ host = document.createElement("div");
+ document.body.appendChild(host);
+ app = createApp(DatabaseBrowser, { connection: oracleJdbcConnection });
+ app.mount(host);
+
+ await vi.waitFor(() => {
+ expect(mocks.listSchemaInfos).toHaveBeenCalledWith(oracleJdbcConnection.id, "");
+ expect(host!.querySelectorAll(".contents > .flex.items-center.text-\\[13px\\]")).toHaveLength(testSchemas.length);
+ });
+
+ // Does not call listDatabases for connection-root schema connections
+ expect(mocks.listDatabases).not.toHaveBeenCalled();
+
+ // Verify row names
+ const renderedNames = Array.from(host.querySelectorAll(".contents > .flex.items-center.text-\\[13px\\]")).map((el) => el.textContent?.trim());
+ expect(renderedNames).toEqual(["APP", "HR", "SALES"]);
+
+ // Double-clicking a row opens object browser with both database and schema
+ const firstRow = host.querySelector<HTMLElement>(".grid.h-\\[34px\\]")!;
+ firstRow.dispatchEvent(new MouseEvent("dblclick", { bubbles: true }));
+ expect(mocks.openObjectBrowser).toHaveBeenCalledWith(oracleJdbcConnection.id, "APP", "APP");
+ });
+
+ it("loads and displays schemas for native Oracle connection", async () => {
+ const nativeOracleConnection: ConnectionConfig = {
+ id: "conn-oracle-native",
+ name: "Oracle Native",
+ db_type: "oracle",
+ };
+
+ host = document.createElement("div");
+ document.body.appendChild(host);
+ app = createApp(DatabaseBrowser, { connection: nativeOracleConnection });
+ app.mount(host);
+
+ await vi.waitFor(() => {
+ expect(mocks.listSchemaInfos).toHaveBeenCalledWith(nativeOracleConnection.id, "");
+ expect(host!.querySelectorAll(".contents > .flex.items-center.text-\\[13px\\]")).toHaveLength(testSchemas.length);
+ });
+ });
+
+ it("falls back to listSchemas when listSchemaInfos rejects", async () => {
+ mocks.listSchemaInfos.mockRejectedValueOnce(new Error("listSchemaInfos unsupported"));
+ mocks.listSchemas.mockResolvedValueOnce(["SCHEMA_1", "SCHEMA_2"]);
+
+ const oracleJdbcConnection: ConnectionConfig = {
+ id: "conn-oracle-jdbc",
+ name: "Oracle JDBC",
+ db_type: "jdbc",
+ jdbc_driver_class: "oracle.jdbc.OracleDriver",
+ };
+
+ host = document.createElement("div");
+ document.body.appendChild(host);
+ app = createApp(DatabaseBrowser, { connection: oracleJdbcConnection });
+ app.mount(host);
+
+ await vi.waitFor(() => {
+ expect(mocks.listSchemaInfos).toHaveBeenCalledWith(oracleJdbcConnection.id, "");
+ expect(mocks.listSchemas).toHaveBeenCalledWith(oracleJdbcConnection.id, "", true);
+ expect(host!.querySelectorAll(".contents > .flex.items-center.text-\\[13px\\]")).toHaveLength(2);
+ });
+ });
+
+ it("calls listDatabases for MySQL connections and does not call listSchemaInfos", async () => {
+ const mysqlConnection: ConnectionConfig = {
+ id: "conn-mysql",
+ name: "MySQL 8.0",
+ db_type: "mysql",
+ };
+
+ host = document.createElement("div");
+ document.body.appendChild(host);
+ app = createApp(DatabaseBrowser, { connection: mysqlConnection });
+ app.mount(host);
+
+ await vi.waitFor(() => {
+ expect(mocks.listDatabases).toHaveBeenCalledWith(mysqlConnection.id);
+ expect(mocks.listSchemaInfos).not.toHaveBeenCalled();
+ expect(host!.querySelectorAll(".contents > .flex.items-center.text-\\[13px\\]")).toHaveLength(testDatabases.length);
+ });
+
+ const firstRow = host.querySelector<HTMLElement>(".grid.h-\\[34px\\]")!;
+ firstRow.dispatchEvent(new MouseEvent("dblclick", { bubbles: true }));
+ expect(mocks.openObjectBrowser).toHaveBeenCalledWith(mysqlConnection.id, "db_mysql", undefined);
+ });
+
+ it("includes system schemas when show_system_schemas is true", async () => {
+ mocks.listSchemaInfos.mockResolvedValueOnce([
+ { name: "APP", comment: null },
+ { name: "SYSTEM", comment: null },
+ ]);
+
+ const oracleConnection: ConnectionConfig = {
+ id: "conn-oracle-sys",
+ name: "Oracle with System Schemas",
+ db_type: "oracle",
+ show_system_schemas: true,
+ };
+
+ host = document.createElement("div");
+ document.body.appendChild(host);
+ app = createApp(DatabaseBrowser, { connection: oracleConnection });
+ app.mount(host);
+
+ await vi.waitFor(() => {
+ expect(host!.querySelectorAll(".contents > .flex.items-center.text-\\[13px\\]")).toHaveLength(2);
+ });
+ const renderedNames = Array.from(host.querySelectorAll(".contents > .flex.items-center.text-\\[13px\\]")).map((el) => el.textContent?.trim());
+ expect(renderedNames).toEqual(["APP", "SYSTEM"]);
+ });
+
+ it("supports Dameng JDBC connections", async () => {
+ const damengJdbcConnection: ConnectionConfig = {
+ id: "conn-dm-jdbc",
+ name: "Dameng DM8 JDBC",
+ db_type: "jdbc",
+ connection_string: "jdbc:dm://127.0.0.1:5236",
+ };
+
+ host = document.createElement("div");
+ document.body.appendChild(host);
+ app = createApp(DatabaseBrowser, { connection: damengJdbcConnection });
+ app.mount(host);
+
+ await vi.waitFor(() => {
+ expect(mocks.listSchemaInfos).toHaveBeenCalledWith(damengJdbcConnection.id, "");
+ expect(host!.querySelectorAll(".contents > .flex.items-center.text-\\[13px\\]")).toHaveLength(testSchemas.length);
+ });
+ });
+
+ it("falls back to listDatabases when schemas return empty list", async () => {
+ mocks.listSchemaInfos.mockResolvedValueOnce([]);
+ mocks.listDatabases.mockResolvedValueOnce([{ name: "FALLBACK_SCHEMA", size_bytes: null, created_at: null, updated_at: null, comment: null, default_charset: null, default_collation: null }]);
+
+ const oracleJdbcConnection: ConnectionConfig = {
+ id: "conn-oracle-empty-schemas",
+ name: "Oracle JDBC Fallback",
+ db_type: "jdbc",
+ connection_string: "jdbc:oracle:thin:@127.0.0.1:1521:xe",
+ };
+
+ host = document.createElement("div");
+ document.body.appendChild(host);
+ app = createApp(DatabaseBrowser, { connection: oracleJdbcConnection });
+ app.mount(host);
+
+ await vi.waitFor(() => {
+ expect(mocks.listSchemaInfos).toHaveBeenCalledWith(oracleJdbcConnection.id, "");
+ expect(mocks.listDatabases).toHaveBeenCalledWith(oracleJdbcConnection.id);
+ expect(host!.querySelectorAll(".contents > .flex.items-center.text-\\[13px\\]")).toHaveLength(1);
+ });
+ });
+});