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(app): separate view source tabs and trim view metadata

t8y26b6f7694fd11
diff --git a/apps/desktop/src/components/sidebar/TreeItem.vue b/apps/desktop/src/components/sidebar/TreeItem.vue
index 45fec3efb6..5298443331 100644
--- a/apps/desktop/src/components/sidebar/TreeItem.vue
+++ b/apps/desktop/src/components/sidebar/TreeItem.vue
@@ -711,7 +711,7 @@ function viewObjectSource() {
return api.getObjectSource(node.connectionId!, node.database!, schema, node.label, objectType as any);
})
.then(async (result) => {
- const tabId = queryStore.createTab(node.connectionId!, node.database!, node.label);
+ const tabId = queryStore.createTab(node.connectionId!, node.database!, `Source - ${node.label}`);
queryStore.updateSql(tabId, result.source);
queryStore.setObjectSource(tabId, {
schema,
diff --git a/apps/desktop/src/stores/connectionStore.ts b/apps/desktop/src/stores/connectionStore.ts
index 679522e29e..c07bfc0e77 100644
--- a/apps/desktop/src/stores/connectionStore.ts
+++ b/apps/desktop/src/stores/connectionStore.ts
@@ -979,7 +979,7 @@ export const useConnectionStore = defineStore("connection", () => {
const node = findNode(treeNodes.value, parentId);
if (!node) return;
- setChildren(node, [
+ const children: TreeNode[] = [
{
id: `${parentId}:__columns`,
label: "tree.columns",
@@ -991,40 +991,47 @@ export const useConnectionStore = defineStore("connection", () => {
isExpanded: false,
children: [],
},
- {
- id: `${parentId}:__indexes`,
- label: "tree.indexes",
- type: "group-indexes",
- connectionId,
- database,
- schema,
- tableName: table,
- isExpanded: false,
- children: [],
- },
- {
- id: `${parentId}:__fkeys`,
- label: "tree.foreignKeys",
- type: "group-fkeys",
- connectionId,
- database,
- schema,
- tableName: table,
- isExpanded: false,
- children: [],
- },
- {
- id: `${parentId}:__triggers`,
- label: "tree.triggers",
- type: "group-triggers",
- connectionId,
- database,
- schema,
- tableName: table,
- isExpanded: false,
- children: [],
- },
- ]);
+ ];
+
+ if (node.type === "table") {
+ children.push(
+ {
+ id: `${parentId}:__indexes`,
+ label: "tree.indexes",
+ type: "group-indexes",
+ connectionId,
+ database,
+ schema,
+ tableName: table,
+ isExpanded: false,
+ children: [],
+ },
+ {
+ id: `${parentId}:__fkeys`,
+ label: "tree.foreignKeys",
+ type: "group-fkeys",
+ connectionId,
+ database,
+ schema,
+ tableName: table,
+ isExpanded: false,
+ children: [],
+ },
+ {
+ id: `${parentId}:__triggers`,
+ label: "tree.triggers",
+ type: "group-triggers",
+ connectionId,
+ database,
+ schema,
+ tableName: table,
+ isExpanded: false,
+ children: [],
+ },
+ );
+ }
+
+ setChildren(node, children);
node.isExpanded = true;
}
diff --git a/apps/desktop/src/stores/queryStore.ts b/apps/desktop/src/stores/queryStore.ts
index 8505e2d076..df8fd5df17 100644
--- a/apps/desktop/src/stores/queryStore.ts
+++ b/apps/desktop/src/stores/queryStore.ts
@@ -107,8 +107,21 @@ export const useQueryStore = defineStore("query", () => {
{ flush: "post" },
);
- function findTabByTitle(connectionId: string, database: string, title: string) {
- return tabs.value.find((t) => t.connectionId === connectionId && t.database === database && t.title === title);
+ function findTabByIdentity(
+ connectionId: string,
+ database: string,
+ title: string,
+ mode: QueryTab["mode"],
+ schema?: string,
+ ) {
+ return tabs.value.find(
+ (tab) =>
+ tab.connectionId === connectionId &&
+ tab.database === database &&
+ tab.title === title &&
+ tab.mode === mode &&
+ (tab.schema || "") === (schema || ""),
+ );
}
function createTab(
@@ -119,7 +132,7 @@ export const useQueryStore = defineStore("query", () => {
schema?: string,
) {
if (title) {
- const existing = findTabByTitle(connectionId, database, title);
+ const existing = findTabByIdentity(connectionId, database, title, mode, schema);
if (existing) {
activeTabId.value = existing.id;
return existing.id;
diff --git a/packages/app-tests/queryStore.test.ts b/packages/app-tests/queryStore.test.ts
index 81ffb0226e..3e7c33e5d4 100644
--- a/packages/app-tests/queryStore.test.ts
+++ b/packages/app-tests/queryStore.test.ts
@@ -118,3 +118,23 @@ test("evicting cached tab results releases multi-result payloads and sessions",
restoreStorage();
}
});
+
+test("tab reuse is scoped by mode and schema instead of title alone", () => {
+ const restoreStorage = installMemoryStorage();
+ try {
+ setActivePinia(createPinia());
+ const store = useQueryStore();
+
+ const dataTabId = store.createTab("conn-1", "db", "users", "data", "public");
+ const sourceTabId = store.createTab("conn-1", "db", "users", "query", "public");
+ const otherSchemaTabId = store.createTab("conn-1", "db", "users", "data", "audit");
+ const reusedDataTabId = store.createTab("conn-1", "db", "users", "data", "public");
+
+ assert.notEqual(sourceTabId, dataTabId);
+ assert.notEqual(otherSchemaTabId, dataTabId);
+ assert.equal(reusedDataTabId, dataTabId);
+ assert.equal(store.tabs.length, 3);
+ } finally {
+ restoreStorage();
+ }
+});
diff --git a/packages/app-tests/tableTree.test.ts b/packages/app-tests/tableTree.test.ts
index 6dc5251523..dbd19d84f8 100644
--- a/packages/app-tests/tableTree.test.ts
+++ b/packages/app-tests/tableTree.test.ts
@@ -183,6 +183,13 @@ test("table expander loads groups by the actual tree node id", () => {
);
});
+test("view metadata groups only expose columns", () => {
+ assert.match(
+ connectionStoreSource,
+ /if \(node\.type === "table"\) \{[\s\S]*type: "group-indexes"[\s\S]*type: "group-fkeys"[\s\S]*type: "group-triggers"/,
+ );
+});
+
test("table metadata group expanders load by their actual tree node ids", () => {
for (const [type, loader] of [
["group-columns", "loadColumns"],