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): show default database for custom drivers

t8y2c6da45486488
diff --git a/apps/desktop/src/components/layout/EditorToolbar.vue b/apps/desktop/src/components/layout/EditorToolbar.vue
index 30d11d7435..2381135b89 100644
--- a/apps/desktop/src/components/layout/EditorToolbar.vue
+++ b/apps/desktop/src/components/layout/EditorToolbar.vue
@@ -25,7 +25,7 @@ import { useSchemaOptions } from "@/composables/useSchemaOptions";
import { connectionIconType } from "@/lib/connectionPresentation";
import { isDefaultDatabase } from "@/lib/defaultDatabase";
import { connectionDisplayName } from "@/lib/tabPresentation";
-import { isSingleDatabase } from "@/lib/databaseCapabilities";
+import { isSingleDatabase, usesTreeSchemaMode } from "@/lib/databaseCapabilities";
import { hexToRgba } from "@/lib/color";
import type { QueryTab, ConnectionConfig } from "@/types/database";
@@ -64,12 +64,17 @@ const activeDatabaseValue = computed(() => props.activeTab.database || "");
const activeConnectionValue = computed(() => props.activeConnection?.id || "");
const activeSchemaValue = computed(() => props.activeTab.schema || "");
const isSingleDb = computed(() => isSingleDatabase(props.activeConnection?.db_type));
+const hasDefaultDatabaseOption = computed(() => activeDatabaseOptions.value.includes(""));
const schemaDatabaseKey = computed(() => props.activeTab.database || (isSingleDb.value ? "_" : ""));
const saveTooltip = computed(() => (props.activeTab.objectSource ? t("objects.saveSource") : t("toolbar.saveSql")));
const showSchemaSelector = computed(() => {
const connection = props.activeConnection;
- return connection && isSchemaAware(connection.id) && (props.activeTab.database || isSingleDb.value);
+ return (
+ connection &&
+ isSchemaAware(connection.id) &&
+ (props.activeTab.database || isSingleDb.value || hasDefaultDatabaseOption.value)
+ );
});
const activeSchemaOptions = computed(() => {
@@ -80,7 +85,7 @@ const activeSchemaOptions = computed(() => {
watchEffect(() => {
const connection = props.activeConnection;
- if (connection && showSchemaSelector.value && schemaDatabaseKey.value) {
+ if (connection && showSchemaSelector.value) {
loadSchemaOptions(connection.id, schemaDatabaseKey.value).catch(() => {});
}
});
@@ -98,6 +103,7 @@ const toolbarStyle = computed(() => {
function databaseDisplayName(database: string): string {
const connection = props.activeConnection;
if (connection?.db_type === "redis" && database !== "") return `db${database}`;
+ if (database === "" && usesTreeSchemaMode(connection?.db_type)) return t("editor.defaultDatabase");
return database || t("editor.noDatabase");
}
diff --git a/apps/desktop/src/components/ui/searchable-select/SearchableSelect.vue b/apps/desktop/src/components/ui/searchable-select/SearchableSelect.vue
index 0191b5c5b6..3eb756dff5 100644
--- a/apps/desktop/src/components/ui/searchable-select/SearchableSelect.vue
+++ b/apps/desktop/src/components/ui/searchable-select/SearchableSelect.vue
@@ -43,7 +43,7 @@ const listContainer = ref<HTMLDivElement>();
const highlightIndex = ref(-1);
const selectedLabel = computed(() => {
- if (!props.modelValue) return props.placeholder;
+ if (!props.modelValue && !props.options.includes("")) return props.placeholder;
return props.displayName(props.modelValue);
});
diff --git a/apps/desktop/src/composables/useDatabaseOptions.ts b/apps/desktop/src/composables/useDatabaseOptions.ts
index ab49acc331..83acbc67cd 100644
--- a/apps/desktop/src/composables/useDatabaseOptions.ts
+++ b/apps/desktop/src/composables/useDatabaseOptions.ts
@@ -1,8 +1,19 @@
import { ref } from "vue";
import { useConnectionStore } from "@/stores/connectionStore";
import { filterDatabaseNamesForConnection } from "@/lib/visibleDatabases";
+import { usesTreeSchemaMode } from "@/lib/databaseCapabilities";
+import type { ConnectionConfig } from "@/types/database";
import * as api from "@/lib/api";
+export function databaseOptionsForConnection(
+ databaseNames: string[],
+ connection: Pick<ConnectionConfig, "db_type" | "visible_databases"> | undefined,
+): string[] {
+ const names = filterDatabaseNamesForConnection(databaseNames, connection);
+ if (names.length === 0 && usesTreeSchemaMode(connection?.db_type)) return [""];
+ return names;
+}
+
export function useDatabaseOptions() {
const connectionStore = useConnectionStore();
@@ -26,7 +37,7 @@ export function useDatabaseOptions() {
);
} else {
const dbs = await api.listDatabases(connectionId);
- databaseOptions.value[connectionId] = filterDatabaseNamesForConnection(
+ databaseOptions.value[connectionId] = databaseOptionsForConnection(
dbs.map((db) => db.name),
connection,
);
diff --git a/apps/desktop/src/composables/useSchemaOptions.ts b/apps/desktop/src/composables/useSchemaOptions.ts
index f177a4c1bf..764b849619 100644
--- a/apps/desktop/src/composables/useSchemaOptions.ts
+++ b/apps/desktop/src/composables/useSchemaOptions.ts
@@ -1,6 +1,6 @@
import { ref } from "vue";
import { useConnectionStore } from "@/stores/connectionStore";
-import { isSchemaAware as isSchemaAwareType, isSingleDatabase } from "@/lib/databaseCapabilities";
+import { isSchemaAware as isSchemaAwareType, isSingleDatabase, usesTreeSchemaMode } from "@/lib/databaseCapabilities";
import * as api from "@/lib/api";
export function hasSchemaOptionsCacheEntry(options: Record<string, string[]>, key: string): boolean {
@@ -24,7 +24,7 @@ export function useSchemaOptions() {
async function loadSchemaOptions(connectionId: string, database: string) {
if (!isSchemaAware(connectionId)) return;
const dbType = connectionStore.getConfig(connectionId)?.db_type;
- if (!database && !isSingleDatabase(dbType)) return;
+ if (!database && !isSingleDatabase(dbType) && !usesTreeSchemaMode(dbType)) return;
const key = cacheKey(connectionId, database);
if (hasSchemaOptionsCacheEntry(schemaOptions.value, key)) return;
if (loadingSchemaOptions.value[key]) return;
diff --git a/packages/app-tests/databaseOptions.test.ts b/packages/app-tests/databaseOptions.test.ts
new file mode 100644
index 0000000000..6991634174
--- /dev/null
+++ b/packages/app-tests/databaseOptions.test.ts
@@ -0,0 +1,15 @@
+import assert from "node:assert/strict";
+import test from "node:test";
+import { databaseOptionsForConnection } from "../../apps/desktop/src/composables/useDatabaseOptions.ts";
+
+test("tree-schema connections include the default database when no catalogs are returned", () => {
+ assert.deepEqual(databaseOptionsForConnection([], { db_type: "jdbc" }), [""]);
+});
+
+test("non tree-schema connections keep an empty database option list", () => {
+ assert.deepEqual(databaseOptionsForConnection([], { db_type: "mysql" }), []);
+});
+
+test("database options preserve returned catalogs when available", () => {
+ assert.deepEqual(databaseOptionsForConnection(["app", "analytics"], { db_type: "jdbc" }), ["app", "analytics"]);
+});