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(connection): show H2 URL placeholder instead of postgresql (#12862) (#12866)

lxk955d1447d1a4152
diff --git a/apps/desktop/src/components/connection/ConnectionDialog.vue b/apps/desktop/src/components/connection/ConnectionDialog.vue
index 821a66d1b9..52e08c35d1 100644
--- a/apps/desktop/src/components/connection/ConnectionDialog.vue
+++ b/apps/desktop/src/components/connection/ConnectionDialog.vue
@@ -3846,7 +3846,12 @@ const isH2FileMode = computed(() => form.value.db_type === "h2" && h2ConnectionM
const isH2CustomDriver = computed(() => form.value.db_type === "h2" && form.value.driver_profile === "h2-custom");
const usesLocalFilePathInput = computed(() => isLocalFileTypeDb(form.value.db_type) && (form.value.db_type !== "h2" || isH2FileMode.value));
-const connectionUrlPlaceholder = computed(() => getUrlPlaceholder(form.value.db_type, form.value.driver_profile));
+const connectionUrlPlaceholder = computed(() => {
+ if (form.value.db_type === "h2") {
+ return isH2FileMode.value ? getUrlPlaceholder("h2", "file") : getUrlPlaceholder("h2", form.value.driver_profile);
+ }
+ return getUrlPlaceholder(form.value.db_type, form.value.driver_profile);
+});
const jdbcUsernamePlaceholder = computed(() => (form.value.driver_profile === "dremio" || isJdbcProductConnection.value ? "" : "sa"));
const filePathPlaceholder = computed(() => {
if (form.value.db_type === "duckdb") return "/path/to/database.duckdb or :memory:";
diff --git a/apps/desktop/src/components/connection/__tests__/ConnectionDialog.h2UrlPlaceholder.spec.ts b/apps/desktop/src/components/connection/__tests__/ConnectionDialog.h2UrlPlaceholder.spec.ts
new file mode 100644
index 0000000000..73e05e6024
--- /dev/null
+++ b/apps/desktop/src/components/connection/__tests__/ConnectionDialog.h2UrlPlaceholder.spec.ts
@@ -0,0 +1,236 @@
+// @vitest-environment happy-dom
+
+import { createApp, defineComponent, h, nextTick, reactive, type App } from "vue";
+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
+import i18n from "@/i18n";
+import type { ConnectionConfig } from "@/types/database";
+
+const visibleTab = vi.hoisted(() => ({ value: "connection" }));
+
+const { store, settings, backend, platformState } = vi.hoisted(() => ({
+ store: {
+ connectionGroupOptions: [],
+ newConnectionGroupId: null,
+ selectedConnectionGroupId: null,
+ addConnection: vi.fn(),
+ updateConnection: vi.fn(),
+ connect: vi.fn(),
+ ensureConnected: vi.fn(),
+ addEphemeralConnection: vi.fn(),
+ removeConnection: vi.fn(),
+ startEditing: vi.fn(),
+ stopEditing: vi.fn(),
+ clearConnectionError: vi.fn(),
+ updateConnectionDatabaseInfo: vi.fn(),
+ applyGlobalTimeouts: vi.fn((config) => config),
+ getConfig: vi.fn(),
+ },
+ settings: {
+ editorSettings: { sidebarShowConnectionNotes: false, globalConnectTimeoutSecs: 10, globalQueryTimeoutSecs: 0 },
+ rememberedDatabaseForConnection: vi.fn(() => ""),
+ persistEditorSettings: vi.fn(),
+ updateEditorSettings: vi.fn(),
+ updateEditorSettingsAndPersist: vi.fn(),
+ },
+ backend: {
+ connectDb: vi.fn(),
+ disconnectDb: vi.fn(),
+ testConnectionWithInfo: vi.fn(),
+ listDatabases: vi.fn(),
+ listPlugins: vi.fn(),
+ listJdbcDrivers: vi.fn(),
+ listJdbcMavenBundles: vi.fn(),
+ listJdbcLocalBundles: vi.fn(),
+ listSshConfigHosts: vi.fn(),
+ listInstalledAgentsLocal: vi.fn(),
+ listenAgentInstallProgress: vi.fn(),
+ },
+ platformState: { windows: true },
+}));
+
+vi.mock("@/stores/connectionStore", () => ({ useConnectionStore: () => store }));
+vi.mock("@/stores/settingsStore", async (original) => ({ ...(await original<typeof import("@/stores/settingsStore")>()), useSettingsStore: () => settings }));
+vi.mock("@/stores/tunnelProfileStore", () => ({ useTunnelProfileStore: () => ({ profiles: [], profileById: () => undefined, init: vi.fn() }) }));
+vi.mock("@/lib/backend/api", async (original) => ({ ...(await original<typeof import("@/lib/backend/api")>()), ...backend }));
+vi.mock("@/lib/backend/tauriRuntime", () => ({ isTauriRuntime: () => false }));
+vi.mock("@/lib/backend/platform", async (original) => ({
+ ...(await original<typeof import("@/lib/backend/platform")>()),
+ isWindows: () => platformState.windows,
+}));
+vi.mock("@/composables/useToast", () => ({ useToast: () => ({ toast: vi.fn() }) }));
+
+vi.mock("@/components/ui/dialog", async () => {
+ const { defineComponent, h } = await import("vue");
+ const passthrough = defineComponent({
+ setup:
+ (_props, { slots }) =>
+ () =>
+ h("div", slots.default?.()),
+ });
+ const Dialog = defineComponent({
+ props: { open: Boolean },
+ emits: ["update:open"],
+ setup:
+ (props, { slots, emit }) =>
+ () =>
+ props.open ? h("section", [h("button", { "data-testid": "dismiss-dialog", onClick: () => emit("update:open", false) }, "Dismiss"), slots.default?.()]) : null,
+ });
+ return { Dialog, DialogContent: passthrough, DialogHeader: passthrough, DialogTitle: passthrough, DialogFooter: passthrough };
+});
+vi.mock("@/components/ui/button", async () => {
+ const { defineComponent, h } = await import("vue");
+ return {
+ Button: defineComponent({
+ inheritAttrs: false,
+ setup:
+ (_props, { attrs, slots }) =>
+ () =>
+ h("button", attrs, slots.default?.()),
+ }),
+ };
+});
+vi.mock("@/components/ui/input", async () => {
+ const { defineComponent, h } = await import("vue");
+ return {
+ Input: defineComponent({
+ props: ["modelValue"],
+ emits: ["update:modelValue"],
+ setup:
+ (props, { attrs, emit }) =>
+ () =>
+ h("input", { ...attrs, value: props.modelValue, onInput: (event: Event) => emit("update:modelValue", (event.target as HTMLInputElement).value) }),
+ }),
+ };
+});
+vi.mock("@/components/ui/PasswordInput.vue", async () => {
+ const { defineComponent, h } = await import("vue");
+ return {
+ default: defineComponent({
+ props: ["modelValue"],
+ setup:
+ (props, { attrs }) =>
+ () =>
+ h("input", { ...attrs, type: "password", value: props.modelValue }),
+ }),
+ };
+});
+vi.mock("@/components/ui/tabs", async () => {
+ const { defineComponent, h } = await import("vue");
+ const pass = defineComponent({
+ setup:
+ (_props, { slots }) =>
+ () =>
+ h("div", slots.default?.()),
+ });
+ const TabsContent = defineComponent({
+ props: ["value"],
+ setup:
+ (props, { slots }) =>
+ () =>
+ props.value === visibleTab.value ? h("div", slots.default?.()) : null,
+ });
+ return { Tabs: pass, TabsContent, TabsList: pass, TabsTrigger: pass };
+});
+vi.mock("@/components/ui/tooltip", async () => {
+ const { defineComponent, h } = await import("vue");
+ const pass = defineComponent({
+ setup:
+ (_props, { slots }) =>
+ () =>
+ h("span", slots.default?.()),
+ });
+ return { HelpTooltip: pass, Tooltip: pass, TooltipContent: pass, TooltipTrigger: pass };
+});
+
+import ConnectionDialog from "@/components/connection/ConnectionDialog.vue";
+
+const mountedApps: App[] = [];
+
+function h2Connection(overrides: Partial<ConnectionConfig> = {}): ConnectionConfig {
+ return {
+ id: "h2-conn",
+ name: "H2 connection",
+ db_type: "h2",
+ driver_profile: "h2",
+ driver_label: "H2",
+ host: "/data/sample.mv.db",
+ port: 0,
+ username: "sa",
+ password: "",
+ database: "sample",
+ save_password: true,
+ ...overrides,
+ } as ConnectionConfig;
+}
+
+async function settle() {
+ for (let i = 0; i < 8; i++) await nextTick();
+}
+
+async function mountDialog(config: ConnectionConfig) {
+ const props = reactive({ open: true, editConfig: config });
+ store.getConfig.mockReturnValue(config);
+ const container = document.createElement("div");
+ document.body.append(container);
+ const app = createApp(
+ defineComponent({
+ setup: () => () =>
+ h(ConnectionDialog, {
+ ...props,
+ "onUpdate:open": (value: boolean) => {
+ props.open = value;
+ },
+ }),
+ }),
+ );
+ app.use(i18n);
+ mountedApps.push(app);
+ app.mount(container);
+ await settle();
+ return props;
+}
+
+function buttonByText(text: string): HTMLButtonElement | undefined {
+ return [...document.querySelectorAll("button")].find((button) => button.textContent?.trim() === text);
+}
+
+function urlInput(): HTMLInputElement | undefined {
+ return [...document.querySelectorAll("input")].find((input) => input.getAttribute("placeholder")?.includes("jdbc:h2:"));
+}
+
+beforeEach(() => {
+ vi.clearAllMocks();
+ platformState.windows = true;
+ i18n.global.locale.value = "en";
+ for (const fn of Object.values(backend)) fn.mockResolvedValue([]);
+ backend.listenAgentInstallProgress.mockResolvedValue(() => {});
+});
+
+afterEach(() => {
+ for (const app of mountedApps.splice(0)) app.unmount();
+ document.body.innerHTML = "";
+});
+
+describe("ConnectionDialog H2 URL placeholder", () => {
+ it("renders file mode placeholder by default and switches to TCP mode placeholder", async () => {
+ await mountDialog(h2Connection());
+
+ const input = urlInput();
+ expect(input).toBeDefined();
+ expect(input?.getAttribute("placeholder")).toBe("jdbc:h2:file:/path/to/database");
+
+ const tcpButton = buttonByText("TCP");
+ expect(tcpButton).toBeDefined();
+ tcpButton?.click();
+ await settle();
+
+ expect(input?.getAttribute("placeholder")).toBe("jdbc:h2:tcp://host:9092/database");
+
+ const fileButton = buttonByText("File");
+ expect(fileButton).toBeDefined();
+ fileButton?.click();
+ await settle();
+
+ expect(input?.getAttribute("placeholder")).toBe("jdbc:h2:file:/path/to/database");
+ });
+});
diff --git a/apps/desktop/src/lib/__tests__/connection/h2ConnectionDialog.spec.ts b/apps/desktop/src/lib/__tests__/connection/h2ConnectionDialog.spec.ts
index 97737ca6c3..d57075536d 100644
--- a/apps/desktop/src/lib/__tests__/connection/h2ConnectionDialog.spec.ts
+++ b/apps/desktop/src/lib/__tests__/connection/h2ConnectionDialog.spec.ts
@@ -1,5 +1,6 @@
import { describe, expect, it } from "vitest";
import { CONNECTION_PICKER_OPTIONS, CONNECTION_PROFILES } from "@/types/generated/connectionProfiles";
+import { connectionUrlPlaceholder } from "@/lib/connection/connectionPresentation";
describe("H2 connection dialog driver profiles", () => {
it("keeps legacy profile hydration without exposing a second H2 catalog entry", () => {
@@ -7,4 +8,10 @@ describe("H2 connection dialog driver profiles", () => {
expect(CONNECTION_PICKER_OPTIONS.find((option) => option.value === "h2")?.category).toBe("lightweight");
expect(CONNECTION_PICKER_OPTIONS.some((option) => option.value === "h2-legacy")).toBe(false);
});
+
+ it("provides H2 connection URL placeholders for TCP and file modes", () => {
+ expect(connectionUrlPlaceholder("h2")).toBe("jdbc:h2:tcp://host:9092/database");
+ expect(connectionUrlPlaceholder("h2", "file")).toBe("jdbc:h2:file:/path/to/database");
+ expect(connectionUrlPlaceholder("h2", "h2")).toBe("jdbc:h2:tcp://host:9092/database");
+ });
});
diff --git a/apps/desktop/src/lib/connection/connectionPresentation.ts b/apps/desktop/src/lib/connection/connectionPresentation.ts
index 7e28de5dc8..999e47c6a9 100644
--- a/apps/desktop/src/lib/connection/connectionPresentation.ts
+++ b/apps/desktop/src/lib/connection/connectionPresentation.ts
@@ -209,6 +209,9 @@ export function connectionUrlPlaceholder(dbType: DatabaseType, driverProfile?: s
case "access":
return "jdbc:ucanaccess:///absolute/path/to/database.accdb";
+ case "h2":
+ return driverProfile === "file" ? "jdbc:h2:file:/path/to/database" : "jdbc:h2:tcp://host:9092/database";
+
case "mongodb":
return "mongodb://user:password@host:port/database";
diff --git a/packages/app-tests/connectionUrl.test.ts b/packages/app-tests/connectionUrl.test.ts
index 5db61c33ad..14a62ecec1 100644
--- a/packages/app-tests/connectionUrl.test.ts
+++ b/packages/app-tests/connectionUrl.test.ts
@@ -61,6 +61,12 @@ test("shows the vendor KingBase URL scheme in the connection form", () => {
assert.equal(connectionUrlPlaceholder("kingbase"), "kingbase8://user:password@host:54321/database");
});
+test("shows the H2 URL scheme in the connection form for tcp and file modes", () => {
+ assert.equal(connectionUrlPlaceholder("h2"), "jdbc:h2:tcp://host:9092/database");
+ assert.equal(connectionUrlPlaceholder("h2", "file"), "jdbc:h2:file:/path/to/database");
+ assert.equal(connectionUrlPlaceholder("h2", "h2"), "jdbc:h2:tcp://host:9092/database");
+});
+
test("applies a credential-free KingBase URL without clearing typed credentials", () => {
const parsed = parseConnectionUrl("kingbase8://172.21.203.70:443/hq_official");
const applied = applyParsedConnectionUrl({ name: "hq", db_type: "kingbase", username: "framework", password: "typed-secret" } as any, parsed);