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
import type { DatabaseType } from "@/types/database";
import { customTypeCapabilities, supportsSchemaIndexManagement, supportsTypeObjectSource } from "@/lib/database/databaseObjectCapabilities";
import { schemaIndexIdentity, schemaIndexIsSameOwner } from "@/lib/table/schemaIndexNavigation";
import type { ObjectBrowserRow } from "@/lib/table/objectBrowserRows";
export type ObjectBrowserRowAction = "table-info" | "index-info" | "index-editor" | "type-info" | "open-table" | "open-source" | "open-source-tab" | "none";
/**
* Determine the action for a single click on an object browser row.
* - TABLE → table-info (show table properties panel)
* - TYPE → type-info (read-only type details) on verified PG-family databases
* - VIEW/MATERIALIZED_VIEW/PROCEDURE/FUNCTION/TRIGGER/SEQUENCE/PACKAGE/PACKAGE_BODY/TYPE_BODY → open-source
* - otherwise → none
*
* TYPE/TYPE_BODY only open source for connections with a real type source
* implementation (Oracle family or Xugu); other databases list types without a DDL getter.
*/
export function singleClickRowAction(row: ObjectBrowserRow | null | undefined, dbType?: DatabaseType): ObjectBrowserRowAction {
if (!row) return "none";
if (dbType === "mongodb") return mongoObjectBrowserRowAction(row);
if (row.type === "INDEX") return supportsSchemaIndexManagement(dbType) && schemaIndexIdentity(row) ? "index-info" : "none";
if (row.type === "TABLE") return "table-info";
if (row.type === "EVENT") return "none";
if (row.type === "TYPE" && customTypeCapabilities(dbType).details) return "type-info";
if (canOpenSource(row, dbType)) return "open-source";
return "none";
}
/**
* Determine the action for a double click on an object browser row.
* - TABLE/VIEW/MATERIALIZED_VIEW → open-table (open data tab, matching the
* sidebar's data-node double-click behavior)
* - PROCEDURE/FUNCTION → open-source-tab (editable source tab; single click keeps the side panel)
* - TRIGGER/SEQUENCE/PACKAGE/PACKAGE_BODY/TYPE/TYPE_BODY → open-source
* - otherwise → none
*/
export function doubleClickRowAction(row: ObjectBrowserRow | null | undefined, dbType?: DatabaseType): ObjectBrowserRowAction {
if (!row) return "none";
if (dbType === "mongodb") return mongoObjectBrowserRowAction(row);
if (row.type === "INDEX") {
if (!supportsSchemaIndexManagement(dbType)) return "none";
const target = schemaIndexIdentity(row);
return schemaIndexIsSameOwner(target) ? "index-editor" : target ? "index-info" : "none";
}
if (row.type === "TABLE" || row.type === "VIEW" || row.type === "MATERIALIZED_VIEW") return "open-table";
if (row.type === "EVENT") return "open-source";
if (row.type === "TYPE" && customTypeCapabilities(dbType).details) return "type-info";
// Routines are the only source-backed rows with a dedicated double-click
// gesture (issue #10202): single click keeps the side panel, double click
// hands the object to the source tab. canOpenSource always accepts them.
if (row.type === "PROCEDURE" || row.type === "FUNCTION") return "open-source-tab";
if (canOpenSource(row, dbType)) return "open-source";
return "none";
}
/**
* Resolve a row click event into a single or double action based on click detail
* and the sidebar activation setting.
*
* In both single-click and double-click activation modes, a single click
* triggers the side-panel action (table-info / open-source). When a distinct
* double-click action exists (e.g. TABLE single→table-info, double→open-table;
* PROCEDURE single→open-source, double→open-source-tab),
* the caller defers the single-click via shouldDeferSingleClick so the second
* click can cancel it.
*/
export function resolveRowClickAction(row: ObjectBrowserRow | null | undefined, detail: number, activation: "single" | "double", dbType?: DatabaseType): { action: ObjectBrowserRowAction; isDouble: boolean } {
if (activation === "double") {
if (detail === 2) return { action: doubleClickRowAction(row, dbType), isDouble: true };
return { action: singleClickRowAction(row, dbType), isDouble: false };
}
// single-click activation
if (detail > 1) return { action: doubleClickRowAction(row, dbType), isDouble: true };
return { action: singleClickRowAction(row, dbType), isDouble: false };
}
/**
* Whether a single-click action should be deferred to distinguish it from a
* possible upcoming double-click. Applies when the row's single-click and
* double-click actions differ (e.g. TABLE: single → table-info, double →
* open-table; PROCEDURE/FUNCTION: single → open-source, double →
* open-source-tab). For rows whose single and double actions are identical
* (e.g. SEQUENCE → open-source both), no deferral is needed.
*/
export function shouldDeferSingleClick(row: ObjectBrowserRow | null | undefined, action: ObjectBrowserRowAction, dbType?: DatabaseType): boolean {
if (action === "none") return false;
const single = singleClickRowAction(row, dbType);
const double = doubleClickRowAction(row, dbType);
return single !== double && action === single;
}
/**
* Objects with source metadata but no supported object-browser mutation API.
* Their menu intentionally exposes only source viewing and copying.
*/
export function isSourceOnlyObjectBrowserRow(row: ObjectBrowserRow): boolean {
return row.type === "TRIGGER" || row.type === "SEQUENCE" || row.type === "PACKAGE" || row.type === "PACKAGE_BODY" || row.type === "TYPE" || row.type === "TYPE_BODY";
}
function mongoObjectBrowserRowAction(row: ObjectBrowserRow): ObjectBrowserRowAction {
return row.type === "TABLE" || row.type === "VIEW" ? "open-table" : "none";
}
function canOpenSource(row: ObjectBrowserRow, dbType?: DatabaseType): boolean {
// Verified custom types open the read-only details panel instead; Oracle
// family types and Xugu also use the source entry below.
if (row.type === "TYPE" && customTypeCapabilities(dbType).details) return false;
if ((row.type === "TYPE" || row.type === "TYPE_BODY") && !supportsTypeObjectSource(dbType)) return false;
return (
row.type === "VIEW" || row.type === "MATERIALIZED_VIEW" || row.type === "PROCEDURE" || row.type === "FUNCTION" || row.type === "TRIGGER" || row.type === "EVENT" || row.type === "SEQUENCE" || row.type === "PACKAGE" || row.type === "PACKAGE_BODY" || row.type === "TYPE" || row.type === "TYPE_BODY"
);
}