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.4 KB
Raw Blame
import { ref } from "vue";

/**
 * Quick-open connection scope: the set of connection ids included in a search.
 * An empty set means "search every connection", which is the default.
 *
 * Deliberately in-memory only: the choice survives closing and reopening the search dialog,
 * but a fresh app launch starts from "all connections" again.
 */
export const quickOpenScopeIds = ref<string[]>([]);

/** True when the user narrowed the search to specific connections. */
export function isQuickOpenScopeActive(ids: readonly string[] = quickOpenScopeIds.value): boolean {
  return ids.length > 0;
}

/** Whether `connectionId` passes the active scope (everything passes when no scope is set). */
export function quickOpenScopeIncludes(connectionId: string, ids: readonly string[] = quickOpenScopeIds.value): boolean {
  return ids.length === 0 || ids.includes(connectionId);
}

export function setQuickOpenScopeIds(ids: string[]): void {
  quickOpenScopeIds.value = [...new Set(ids.filter((id) => typeof id === "string" && id.trim().length > 0))];
}

/** Drop stored ids whose connection no longer exists, so a stale scope cannot hide everything. */
export function pruneQuickOpenScope(knownConnectionIds: readonly string[]): void {
  if (!isQuickOpenScopeActive()) return;
  const known = new Set(knownConnectionIds);
  const next = quickOpenScopeIds.value.filter((id) => known.has(id));
  if (next.length !== quickOpenScopeIds.value.length) setQuickOpenScopeIds(next);
}