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(milvus): list all databases and their collections in sidebar

hhzorg95b7b8b9a37d
diff --git a/apps/desktop/src/components/layout/ContentArea.vue b/apps/desktop/src/components/layout/ContentArea.vue
index cbac95fbf2..5912e6f02d 100644
--- a/apps/desktop/src/components/layout/ContentArea.vue
+++ b/apps/desktop/src/components/layout/ContentArea.vue
@@ -230,7 +230,9 @@ function increaseTableFontSize() {
const activeTabDimension = computed(() => {
const tab = props.activeTab;
if (!tab.connectionId || tab.mode !== "vector") return undefined;
- const nodeId = `${tab.connectionId}:__vector_collection:${tab.sql}`;
+ const isMilvus = connectionStore.getConfig(tab.connectionId)?.db_type === "milvus";
+ const suffix = isMilvus && tab.database ? `${tab.database}:${tab.sql}` : tab.sql;
+ const nodeId = `${tab.connectionId}:__vector_collection:${suffix}`;
const meta = findNodeInTree(connectionStore.treeNodes, nodeId)?.meta;
return meta && "dimension" in meta ? (meta as VectorCollectionMeta).dimension : undefined;
});
diff --git a/apps/desktop/src/components/sidebar/TreeItem.vue b/apps/desktop/src/components/sidebar/TreeItem.vue
index 787db9293c..088463c2e3 100644
--- a/apps/desktop/src/components/sidebar/TreeItem.vue
+++ b/apps/desktop/src/components/sidebar/TreeItem.vue
@@ -580,7 +580,9 @@ async function toggle() {
await connectionStore.loadMongoDatabases(node.connectionId);
} else if (config?.db_type === "elasticsearch") {
await connectionStore.loadElasticsearchIndices(node.connectionId);
- } else if (config?.db_type === "qdrant" || config?.db_type === "milvus" || config?.db_type === "weaviate" || config?.db_type === "chromadb") {
+ } else if (config?.db_type === "milvus") {
+ await connectionStore.loadMilvusDatabases(node.connectionId);
+ } else if (config?.db_type === "qdrant" || config?.db_type === "weaviate" || config?.db_type === "chromadb") {
await connectionStore.loadVectorCollections(node.connectionId);
} else if (config?.db_type === "mq") {
await connectionStore.loadMqTenants(node.connectionId);
@@ -614,6 +616,8 @@ async function toggle() {
queryStore.openUserAdmin(node.connectionId);
} else if (node.type === "mongo-db" && node.connectionId && node.database) {
await connectionStore.loadMongoCollections(node.connectionId, node.database);
+ } else if (node.type === "vector-database" && node.connectionId && node.database) {
+ await connectionStore.loadVectorCollections(node.connectionId, node.database);
} else if (node.type === "mongo-collection" && node.connectionId && node.database) {
await connectionStore.loadTableGroups(node.connectionId, node.database, node.label, node.schema, node.id);
} else if (node.type === "elasticsearch-index" && node.connectionId) {
@@ -622,7 +626,7 @@ async function toggle() {
queryStore.updateSql(tab, node.label);
} else if (node.type === "vector-collection" && node.connectionId) {
await connectionStore.ensureConnected(node.connectionId);
- const collectionRef = node.id.includes("__vector_collection:") ? node.id.split("__vector_collection:").pop() || node.label : node.label;
+ const collectionRef = (node.meta as { collectionId?: string } | undefined)?.collectionId ?? node.label;
const tab = queryStore.createTab(node.connectionId, node.database || "default", node.label, "vector");
queryStore.updateSql(tab, collectionRef);
api
diff --git a/apps/desktop/src/lib/sidebar/sidebarActiveTabTarget.ts b/apps/desktop/src/lib/sidebar/sidebarActiveTabTarget.ts
index 54302d243f..283eb1328f 100644
--- a/apps/desktop/src/lib/sidebar/sidebarActiveTabTarget.ts
+++ b/apps/desktop/src/lib/sidebar/sidebarActiveTabTarget.ts
@@ -23,6 +23,7 @@ export type ActiveTabSidebarTarget =
| {
type: "vector-collection";
connectionId: string;
+ database: string;
collectionName: string;
}
| {
@@ -102,6 +103,7 @@ export function activeTabSidebarTarget(tab: QueryTab | undefined | null): Active
return {
type: "vector-collection",
connectionId: tab.connectionId,
+ database: tab.database,
collectionName,
};
}
@@ -157,7 +159,7 @@ export function matchesTarget(node: TreeNode, target: ActiveTabSidebarTarget): b
}
if (target.type === "vector-collection") {
- return node.type === "vector-collection" && node.connectionId === target.connectionId && node.label === target.collectionName;
+ return node.type === "vector-collection" && node.connectionId === target.connectionId && node.database === target.database && node.label === target.collectionName;
}
if (target.type === "query-context") {
diff --git a/apps/desktop/src/lib/sidebar/sidebarDatabaseOpenState.ts b/apps/desktop/src/lib/sidebar/sidebarDatabaseOpenState.ts
index 68799a1a6a..740d88d4c5 100644
--- a/apps/desktop/src/lib/sidebar/sidebarDatabaseOpenState.ts
+++ b/apps/desktop/src/lib/sidebar/sidebarDatabaseOpenState.ts
@@ -1,7 +1,7 @@
import type { TreeNode } from "@/types/database";
export function isSidebarDatabaseOpened(node: TreeNode, isTreeNodeChildrenLoaded: (nodeId: string) => boolean): boolean {
- return (node.type === "database" || node.type === "mongo-db") && !!node.connectionId && node.database != null && isTreeNodeChildrenLoaded(node.id);
+ return (node.type === "database" || node.type === "mongo-db" || node.type === "vector-database") && !!node.connectionId && node.database != null && isTreeNodeChildrenLoaded(node.id);
}
export function canCloseSidebarDatabaseConnection(node: TreeNode, isTreeNodeChildrenLoaded: (nodeId: string) => boolean): boolean {
diff --git a/apps/desktop/src/lib/sidebar/sidebarNodeOrdering.ts b/apps/desktop/src/lib/sidebar/sidebarNodeOrdering.ts
index 8ae66ab88a..c08e20a204 100644
--- a/apps/desktop/src/lib/sidebar/sidebarNodeOrdering.ts
+++ b/apps/desktop/src/lib/sidebar/sidebarNodeOrdering.ts
@@ -26,6 +26,10 @@ export function sortSidebarTreeChildrenForParent(parent: Pick<TreeNode, "type">,
return [...gridFsNodes, ...sortByLabel(collections)];
}
+ if (parent.type === "vector-database") {
+ return sortByLabel(normalized);
+ }
+
if (parent.type === "mongo-buckets") {
return sortByLabel(normalized);
}
diff --git a/apps/desktop/src/lib/sidebar/treeNodeIcon.ts b/apps/desktop/src/lib/sidebar/treeNodeIcon.ts
index 13aa26e536..b83a317d6c 100644
--- a/apps/desktop/src/lib/sidebar/treeNodeIcon.ts
+++ b/apps/desktop/src/lib/sidebar/treeNodeIcon.ts
@@ -15,6 +15,8 @@ export function getTreeNodeIconInfo(node: TreeNode): TreeNodeIconInfo | null {
case "database":
case "mongo-db":
return { icon: Database, colorClass: "text-yellow-500" };
+ case "vector-database":
+ return { icon: Database, colorClass: "text-cyan-500" };
case "linked-server-root":
return { icon: Network, colorClass: "text-blue-500" };
case "linked-server":
diff --git a/apps/desktop/src/stores/connectionStore.ts b/apps/desktop/src/stores/connectionStore.ts
index 953bec8645..a67eb1432e 100644
--- a/apps/desktop/src/stores/connectionStore.ts
+++ b/apps/desktop/src/stores/connectionStore.ts
@@ -1,7 +1,7 @@
import { defineStore } from "pinia";
import { uuid } from "@/lib/common/utils";
import { ref, computed, watch } from "vue";
-import type { ColumnInfo, CompletionAssistantCandidate, CompletionAssistantObjectKind, CompletionAssistantRequest, ConnectionConfig, ForeignKeyInfo, ObjectInfo, SchemaInfo, SidebarLayout, TableInfo, TreeNode } from "@/types/database";
+import type { ColumnInfo, CompletionAssistantCandidate, CompletionAssistantObjectKind, CompletionAssistantRequest, ConnectionConfig, ForeignKeyInfo, ObjectInfo, SchemaInfo, SidebarLayout, TableInfo, TreeNode, VectorCollectionMeta } from "@/types/database";
import { applyPinnedTreeNodeState, updatePinnedTreeNodeInPlace } from "@/lib/app/pinnedItems";
import {
reconcileLayout,
@@ -1718,7 +1718,9 @@ export const useConnectionStore = defineStore("connection", () => {
await loadMongoDatabases(connectionId);
} else if (config.db_type === "elasticsearch") {
await loadElasticsearchIndices(connectionId);
- } else if (config.db_type === "qdrant" || config.db_type === "milvus" || config.db_type === "weaviate" || config.db_type === "chromadb") {
+ } else if (config.db_type === "milvus") {
+ await loadMilvusDatabases(connectionId);
+ } else if (config.db_type === "qdrant" || config.db_type === "weaviate" || config.db_type === "chromadb") {
await loadVectorCollections(connectionId);
} else if (config.db_type === "mq") {
await loadMqTenants(connectionId, { force: true });
@@ -2349,29 +2351,26 @@ export const useConnectionStore = defineStore("connection", () => {
}
}
- async function loadVectorCollections(connectionId: string) {
+ async function loadMilvusDatabases(connectionId: string) {
const node = findNode(treeNodes.value, connectionId);
if (!node) return;
- const config = getConfig(connectionId);
- const database = config?.database || "default";
node.isLoading = true;
try {
await ensureConnected(connectionId);
- const collections = await withMetadataLoadTimeout(connectionId, api.vectorListCollections(connectionId, database), "vector collections");
- const sorted = [...collections].sort((a, b) => a.name.localeCompare(b.name));
+ const dbs = await withMetadataLoadTimeout(connectionId, api.documentListDatabases(connectionId), "Milvus databases");
setChildren(
node,
withSavedSqlRoot(
connectionId,
- sorted.map((info) => ({
- id: `${connectionId}:__vector_collection:${info.id}`,
- label: info.name,
- type: "vector-collection" as const,
+ sortSidebarNames(dbs).map((db) => ({
+ id: `${connectionId}:${db}`,
+ label: db,
+ type: "vector-database" as const,
connectionId,
- database,
+ database: db,
isExpanded: false,
- meta: info.dimension != null ? { dimension: info.dimension } : undefined,
+ children: [],
})),
node,
),
@@ -2385,6 +2384,39 @@ export const useConnectionStore = defineStore("connection", () => {
}
}
+ async function loadVectorCollections(connectionId: string, database?: string) {
+ const config = getConfig(connectionId);
+ const isMilvus = config?.db_type === "milvus";
+ const effectiveDb = database || config?.database || "default";
+ // Milvus groups collections under a per-database node; other vector stores stay flat under the connection.
+ const node = isMilvus && database ? findNode(treeNodes.value, `${connectionId}:${database}`) : findNode(treeNodes.value, connectionId);
+ if (!node) return;
+
+ node.isLoading = true;
+ try {
+ await ensureConnected(connectionId);
+ const collections = await withMetadataLoadTimeout(connectionId, api.vectorListCollections(connectionId, effectiveDb), "vector collections");
+ const sorted = [...collections].sort((a, b) => a.name.localeCompare(b.name));
+ const collectionChildren = sorted.map((info) => ({
+ // Include the database for Milvus so same-named collections across databases don't collide.
+ id: `${connectionId}:__vector_collection:${isMilvus ? `${effectiveDb}:${info.id}` : info.id}`,
+ label: info.name,
+ type: "vector-collection" as const,
+ connectionId,
+ database: effectiveDb,
+ isExpanded: false,
+ meta: { dimension: info.dimension, collectionId: info.id } as VectorCollectionMeta,
+ }));
+ setChildren(node, isMilvus && database ? collectionChildren : withSavedSqlRoot(connectionId, collectionChildren, node));
+ node.isExpanded = true;
+ } catch (e) {
+ recordMetadataLoadError(connectionId, e);
+ throw e;
+ } finally {
+ node.isLoading = false;
+ }
+ }
+
async function loadMongoCollections(connectionId: string, database: string) {
const nodeId = `${connectionId}:${database}`;
const node = findNode(treeNodes.value, nodeId);
@@ -3387,7 +3419,9 @@ export const useConnectionStore = defineStore("connection", () => {
await loadMongoDatabases(node.connectionId);
} else if (config?.db_type === "elasticsearch") {
await loadElasticsearchIndices(node.connectionId);
- } else if (config?.db_type === "qdrant" || config?.db_type === "milvus" || config?.db_type === "weaviate" || config?.db_type === "chromadb") {
+ } else if (config?.db_type === "milvus") {
+ await loadMilvusDatabases(node.connectionId);
+ } else if (config?.db_type === "qdrant" || config?.db_type === "weaviate" || config?.db_type === "chromadb") {
await loadVectorCollections(node.connectionId);
} else if (config?.db_type === "mq") {
await loadMqTenants(node.connectionId, options);
@@ -3398,6 +3432,8 @@ export const useConnectionStore = defineStore("connection", () => {
}
} 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) {
+ await loadVectorCollections(node.connectionId, node.database);
} else if (node.type === "mongo-collection" && node.connectionId && node.database) {
await loadTableGroups(node.connectionId, node.database, node.label, node.schema, node.id);
} else if (node.type === "mongo-gridfs") {
@@ -4765,6 +4801,7 @@ export const useConnectionStore = defineStore("connection", () => {
loadNacosNamespaces,
updateRedisDbKeyStats,
loadMongoDatabases,
+ loadMilvusDatabases,
loadElasticsearchIndices,
loadVectorCollections,
loadMongoCollections,
diff --git a/apps/desktop/src/types/database.ts b/apps/desktop/src/types/database.ts
index a82f0575cd..c225c4183a 100644
--- a/apps/desktop/src/types/database.ts
+++ b/apps/desktop/src/types/database.ts
@@ -556,6 +556,7 @@ export type TreeNodeType =
| "mongo-buckets"
| "mongo-bucket"
| "mongo-collection"
+ | "vector-database"
| "vector-collection"
| "elasticsearch-index";
@@ -780,6 +781,7 @@ export interface SavedSqlLibrary {
export interface VectorCollectionMeta {
dimension?: number;
+ collectionId?: string;
}
export interface CollectionInfo {
diff --git a/crates/dbx-core/src/db/vector_driver.rs b/crates/dbx-core/src/db/vector_driver.rs
index a038a5eac0..3d413e0473 100644
--- a/crates/dbx-core/src/db/vector_driver.rs
+++ b/crates/dbx-core/src/db/vector_driver.rs
@@ -171,6 +171,40 @@ pub(crate) async fn list_collections_with_db(
}
}
+/// List databases for a vector connection.
+/// Milvus supports multiple databases; other vector stores expose a single "default" namespace.
+pub async fn list_databases(client: &VectorClient) -> Result<Vec<String>, String> {
+ match client.kind {
+ VectorDbKind::Milvus => list_milvus_databases(client).await,
+ _ => Ok(vec!["default".to_string()]),
+ }
+}
+
+async fn list_milvus_databases(client: &VectorClient) -> Result<Vec<String>, String> {
+ // Older Milvus versions (pre-2.2) do not expose the databases endpoint; fall back to "default"
+ // so the connection stays browsable instead of failing the whole tree load.
+ let body = match send_json(client.post("/v2/vectordb/databases/list"), "Milvus").await {
+ Ok(body) => body,
+ Err(_) => return Ok(vec!["default".to_string()]),
+ };
+ let mut names: Vec<String> = match body.get("data") {
+ Some(Value::Array(items)) => items.iter().filter_map(milvus_database_name_from_item).collect(),
+ _ => Vec::new(),
+ };
+ if !names.iter().any(|name| name == "default") {
+ names.push("default".to_string());
+ }
+ names.sort_by(|a, b| a.cmp(b));
+ Ok(names)
+}
+
+fn milvus_database_name_from_item(item: &Value) -> Option<String> {
+ item.as_str()
+ .map(str::to_string)
+ .or_else(|| item.get("dbName").and_then(Value::as_str).map(str::to_string))
+ .or_else(|| item.get("name").and_then(Value::as_str).map(str::to_string))
+}
+
async fn list_qdrant_collections(client: &VectorClient) -> Result<Vec<CollectionInfo>, String> {
let body = send_json(client.get("/collections"), "Qdrant").await?;
let mut infos: Vec<CollectionInfo> = body
@@ -441,6 +475,7 @@ fn weaviate_collection_names_from_schema(body: &Value) -> Vec<String> {
pub async fn find_documents(
client: &VectorClient,
+ database: &str,
collection: &str,
skip: u64,
limit: i64,
@@ -498,7 +533,7 @@ pub async fn find_documents(
VectorDbKind::Milvus => format!(
"POST /v2/vectordb/entities/query\n{}",
serde_json::json!({
- "dbName": "default",
+ "dbName": if database.is_empty() { "default" } else { database },
"collectionName": collection,
"filter": "",
"limit": limit.max(1) as u64,
diff --git a/crates/dbx-core/src/document_ops.rs b/crates/dbx-core/src/document_ops.rs
index 8a1ac98b41..427ab5813d 100644
--- a/crates/dbx-core/src/document_ops.rs
+++ b/crates/dbx-core/src/document_ops.rs
@@ -52,7 +52,8 @@ pub async fn list_databases_core(state: &AppState, connection_id: &str) -> Resul
}
Err(error) => Err(error),
},
- PoolKind::Elasticsearch(_) | PoolKind::VectorDb(_) => Ok(vec!["default".to_string()]),
+ PoolKind::Elasticsearch(_) => Ok(vec!["default".to_string()]),
+ PoolKind::VectorDb(client) => vector_driver::list_databases(&client).await,
PoolKind::Agent(client) => {
let mut client = client.lock().await;
match client.mongo_list_databases::<Vec<serde_json::Value>>().await {
@@ -376,8 +377,8 @@ pub async fn find_documents_core(
PoolKind::VectorDb(client) => {
let client = client.clone();
drop(connections);
- let _ = (database, filter, sort);
- vector_driver::find_documents(&client, collection, skip, limit).await
+ let _ = (filter, sort);
+ vector_driver::find_documents(&client, database, collection, skip, limit).await
}
PoolKind::Agent(client) => {
let mut client = client.lock().await;