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.5 KB
Raw Blame
import { metadataLoadBudgetMs, waitForMetadata } from "@/lib/metadata/metadataLoadBudget";

export interface VisibleDatabasesPickerDraft {
  /** Opens the one-time draft connection the picker lists its objects from. */
  connect: () => Promise<unknown>;
  /** Reads the visible object names (databases or schemas) through that draft. */
  listNames: () => Promise<string[]>;
  /** Releases the draft connection; best-effort, it never blocks the dialog. */
  disconnect: () => Promise<void>;
  /** Effective query timeout of the draft, used to derive the local load budget. */
  queryTimeoutSecs?: number | undefined;
}

/**
 * Loads the names shown by the connection dialog's "visible objects" picker.
 *
 * Every step is bounded by the local metadata load budget, and releasing the draft
 * connection is best-effort. A server (or a proxy in front of it) that answers the
 * connection probe but stays silent for `CONFIG`/`INFO` used to leave the picker
 * spinning with the rest of the dialog disabled, because nothing along this path
 * cancelled the wait (#12426).
 */
export async function loadVisibleDatabasesPickerNames(draft: VisibleDatabasesPickerDraft): Promise<string[]> {
  const budgetMs = metadataLoadBudgetMs(draft.queryTimeoutSecs);
  try {
    await waitForMetadata(draft.connect(), budgetMs);
    return await waitForMetadata(draft.listNames(), budgetMs);
  } finally {
    try {
      void draft.disconnect().catch(() => undefined);
    } catch {
      // A synchronous teardown failure must not replace the load result.
    }
  }
}