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。
TypeScript aicliclickhousedatabasedatabase-clientdatabase-managementdockerguimcpmongodbmysqlpostgresqlredisrustsql-serversqlitetaurivue
fix(objects): stabilize object browser row ids
t8y2c5fc31c21805
diff --git a/apps/desktop/src/components/objects/ObjectBrowser.vue b/apps/desktop/src/components/objects/ObjectBrowser.vueindex 692a466d3d..8e7115aa05 100644--- a/apps/desktop/src/components/objects/ObjectBrowser.vue+++ b/apps/desktop/src/components/objects/ObjectBrowser.vue@@ -33,7 +33,6 @@ import * as api from "@/lib/api";import type { ConnectionConfig, ObjectInfo, ObjectSourceKind } from "@/types/database";import { isSchemaAware } from "@/lib/databaseCapabilities";import { buildTableSelectSql, qualifiedTableName } from "@/lib/tableSelectSql";-import { normalizeDatabaseObjectName } from "@/lib/tableTree";import { useToast } from "@/composables/useToast";import { buildExecutableObjectSourceStatements, objectSourceSaveExecutionMode } from "@/lib/objectSourceEditor";import { buildRenameObjectSql, supportsObjectRename } from "@/lib/objectRenameSql";@@ -43,14 +42,7 @@ import QueryEditor from "@/components/editor/QueryEditor.vue";import type { SqlFormatDialect } from "@/lib/sqlFormatter";import { isCancelSearchShortcut } from "@/lib/keyboardShortcuts";import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle } from "@/components/ui/dialog";--type ObjectRow = {- id: string;- name: string;- schema?: string;- type: "TABLE" | "VIEW" | "PROCEDURE" | "FUNCTION";- comment?: string | null;-};+import { buildObjectBrowserRows, type ObjectBrowserRow } from "@/lib/objectBrowserRows";type ObjectFilter = "all" | "tables" | "views" | "procedures" | "functions";@@ -72,7 +64,7 @@ const queryStore = useQueryStore();const schemas = ref<string[]>([]);const selectedSchema = ref<string | undefined>(props.schema);-const rows = ref<ObjectRow[]>([]);+const rows = ref<ObjectBrowserRow[]>([]);const rootRef = ref<HTMLElement>();const search = ref("");const objectFilter = ref<ObjectFilter>("all");@@ -81,16 +73,16 @@ const loadingObjects = ref(false);const sourceLoading = ref(false);const sourceContent = ref("");const sourceError = ref("");-const sourceRow = ref<ObjectRow | null>(null);+const sourceRow = ref<ObjectBrowserRow | null>(null);const sourceEditing = ref(false);const sourceDraft = ref("");const sourceSaving = ref(false);const sourceSaveError = ref("");const error = ref("");const showDropConfirm = ref(false);-const dropTarget = ref<ObjectRow | null>(null);+const dropTarget = ref<ObjectBrowserRow | null>(null);const showRenameDialog = ref(false);-const renameTarget = ref<ObjectRow | null>(null);+const renameTarget = ref<ObjectBrowserRow | null>(null);const renameInput = ref("");const renameError = ref("");let loadId = 0;@@ -151,49 +143,41 @@ const filteredRows = computed(() => {return searchedRows.value;});-function normalizeType(type: string): ObjectRow["type"] {- const value = type.toUpperCase();- if (value.includes("VIEW")) return "VIEW";- if (value.includes("PROC")) return "PROCEDURE";- if (value.includes("FUNC")) return "FUNCTION";- return "TABLE";-}--function iconFor(row: ObjectRow) {+function iconFor(row: ObjectBrowserRow) {if (row.type === "VIEW") return Eye;if (row.type === "PROCEDURE") return ScrollText;if (row.type === "FUNCTION") return Braces;return Table2;}-function typeLabel(type: ObjectRow["type"]) {+function typeLabel(type: ObjectBrowserRow["type"]) {if (type === "VIEW") return t("objects.view");if (type === "PROCEDURE") return t("objects.procedure");if (type === "FUNCTION") return t("objects.function");return t("objects.table");}-function iconClass(type: ObjectRow["type"]) {+function iconClass(type: ObjectBrowserRow["type"]) {if (type === "VIEW") return "text-purple-500";if (type === "PROCEDURE") return "text-blue-500";if (type === "FUNCTION") return "text-amber-500";return "text-green-500";}-function canOpenSource(row: ObjectRow) {+function canOpenSource(row: ObjectBrowserRow) {return row.type === "VIEW" || row.type === "PROCEDURE" || row.type === "FUNCTION";}-function canRename(row: ObjectRow) {+function canRename(row: ObjectBrowserRow) {return supportsObjectRename(props.connection.db_type, row.type);}-function sourceTitle(row: ObjectRow | null) {+function sourceTitle(row: ObjectBrowserRow | null) {if (!row) return t("objects.source");return `${row.name} ${t("objects.source")}`;}-function openRow(row: ObjectRow) {+function openRow(row: ObjectBrowserRow) {if (row.type === "TABLE") {emit("openTable", { tableName: row.name, schema: row.schema });return;@@ -203,7 +187,7 @@ function openRow(row: ObjectRow) {}}-async function openSource(row: ObjectRow) {+async function openSource(row: ObjectBrowserRow) {sourceRow.value = row;sourceContent.value = "";sourceError.value = "";@@ -229,7 +213,7 @@ async function openSource(row: ObjectRow) {}}-function openNewQuery(row: ObjectRow) {+function openNewQuery(row: ObjectBrowserRow) {const tabId = queryStore.createTab(props.connection.id, props.database, row.name);queryStore.updateSql(tabId,@@ -242,7 +226,7 @@ function openNewQuery(row: ObjectRow) {);}-function qualifiedName(row: ObjectRow): string {+function qualifiedName(row: ObjectBrowserRow): string {return qualifiedTableName({databaseType: props.connection.db_type,schema: row.schema || selectedSchema.value,@@ -250,12 +234,12 @@ function qualifiedName(row: ObjectRow): string {});}-function requestDrop(row: ObjectRow) {+function requestDrop(row: ObjectBrowserRow) {dropTarget.value = row;showDropConfirm.value = true;}-function requestRename(row: ObjectRow) {+function requestRename(row: ObjectBrowserRow) {renameTarget.value = row;renameInput.value = row.name;renameError.value = "";@@ -449,19 +433,11 @@ async function loadObjects() {const schema = needsSchema.value ? selectedSchema.value || "" : props.database;const objects: ObjectInfo[] = await api.listObjects(props.connection.id, props.database, schema);if (id !== loadId) return;- rows.value = objects.flatMap((object) => {- const name = normalizeDatabaseObjectName(object.name);- if (!name) return [];- const objectSchema = object.schema ? normalizeDatabaseObjectName(object.schema) : undefined;- return [- {- id: `${objectSchema || schema || props.database}:${name}:${object.object_type}`,- name,- schema: objectSchema || (needsSchema.value ? schema : undefined),- type: normalizeType(object.object_type),- comment: object.comment,- },- ];+ rows.value = buildObjectBrowserRows({+ objects,+ database: props.database,+ fallbackSchema: schema,+ needsSchema: needsSchema.value,});} catch (e: any) {if (id !== loadId) return;diff --git a/apps/desktop/src/lib/objectBrowserRows.ts b/apps/desktop/src/lib/objectBrowserRows.tsnew file mode 100644index 0000000000..6e97b23164--- /dev/null+++ b/apps/desktop/src/lib/objectBrowserRows.ts@@ -0,0 +1,46 @@+import type { ObjectInfo } from "@/types/database";+import { normalizeDatabaseObjectName } from "@/lib/tableTree";++export type ObjectBrowserRow = {+ id: string;+ name: string;+ schema?: string;+ type: "TABLE" | "VIEW" | "PROCEDURE" | "FUNCTION";+ comment?: string | null;+};++export function normalizeObjectBrowserType(type: string): ObjectBrowserRow["type"] {+ const value = type.toUpperCase();+ if (value.includes("VIEW")) return "VIEW";+ if (value.includes("PROC")) return "PROCEDURE";+ if (value.includes("FUNC")) return "FUNCTION";+ return "TABLE";+}++export function buildObjectBrowserRows(options: {+ objects: ObjectInfo[];+ database: string;+ fallbackSchema: string;+ needsSchema: boolean;+}): ObjectBrowserRow[] {+ const seen = new Map<string, number>();+ return options.objects.flatMap((object) => {+ const name = normalizeDatabaseObjectName(object.name);+ if (!name) return [];+ const objectSchema = object.schema ? normalizeDatabaseObjectName(object.schema) : undefined;+ const schema = objectSchema || (options.needsSchema ? options.fallbackSchema : undefined);+ const type = normalizeObjectBrowserType(object.object_type);+ const baseId = `${schema || options.fallbackSchema || options.database}:${name}:${type}`;+ const index = seen.get(baseId) ?? 0;+ seen.set(baseId, index + 1);+ return [+ {+ id: `${baseId}:${index}`,+ name,+ schema,+ type,+ comment: object.comment,+ },+ ];+ });+}diff --git a/packages/app-tests/objectBrowserRows.test.ts b/packages/app-tests/objectBrowserRows.test.tsnew file mode 100644index 0000000000..91f2a77f7f--- /dev/null+++ b/packages/app-tests/objectBrowserRows.test.ts@@ -0,0 +1,21 @@+import { strict as assert } from "node:assert";+import test from "node:test";+import { buildObjectBrowserRows } from "../../apps/desktop/src/lib/objectBrowserRows.ts";++test("builds unique row ids for overloaded routines with the same visible name", () => {+ const rows = buildObjectBrowserRows({+ objects: [+ { name: "list_pipes", object_type: "FUNCTION", schema: "dbms_pipe" },+ { name: "list_pipes", object_type: "FUNCTION", schema: "dbms_pipe" },+ { name: "create_pipe", object_type: "FUNCTION", schema: "dbms_pipe" },+ ],+ database: "highgo",+ fallbackSchema: "dbms_pipe",+ needsSchema: true,+ });++ assert.deepEqual(+ rows.map((row) => row.id),+ ["dbms_pipe:list_pipes:FUNCTION:0", "dbms_pipe:list_pipes:FUNCTION:1", "dbms_pipe:create_pipe:FUNCTION:0"],+ );+});