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。

1.1 KB
Raw Blame
import type { TreeNode, TreeNodeType } from "@/types/database";

// Row types whose single-click action opens the object's data. Pressing Enter
// in the sidebar search opens the first matching one of these.
const sidebarSearchOpenFirstNodeTypes = new Set<TreeNodeType>(["table", "view", "materialized_view"]);

/** True when any sidebar search surface (global query or per-database table search) is active. */
export function hasActiveSidebarSearch(globalQuery: string, tableSearchQueries: Readonly<Record<string, string>>): boolean {
  if (globalQuery.trim().length > 0) return true;
  return Object.values(tableSearchQueries).some((query) => query.trim().length > 0);
}

/**
 * The first visible data node a search should open on Enter, in tree display
 * order. Returns null when no table-like row is visible.
 */
export function firstSidebarSearchMatchDataNode(nodes: readonly TreeNode[], hasActiveSearch: boolean): TreeNode | null {
  if (!hasActiveSearch) return null;
  for (const node of nodes) {
    if (sidebarSearchOpenFirstNodeTypes.has(node.type)) return node;
  }
  return null;
}