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.8 KB
Raw Blame
import { reactive, toRaw } from "vue";

/**
 * Build a per-open dialog controller without unwrapping shared dialog refs.
 *
 * Spreading a reactive controller (`{ ...controller }`) unwraps nested refs into
 * plain booleans. The dialog UI then mutates a disconnected copy, while actions
 * still write the module-level refs — so cancel leaves `showCreateDatabaseDialog`
 * stuck `true`, and the next sidebar right-click remounts an already-open dialog.
 */
export function createRoutedSidebarDialogController(
  controller: Record<string, unknown>,
  options: {
    node: unknown;
    wrapAction: (action: (...args: unknown[]) => unknown) => (...args: unknown[]) => unknown;
  },
): Record<string, any> {
  const routedController = reactive<Record<string, any>>({});
  for (const [key, value] of Object.entries(toRaw(controller))) {
    if (key === "node") continue;
    if (typeof value === "function") {
      routedController[key] = options.wrapAction(value as (...args: unknown[]) => unknown);
      continue;
    }
    routedController[key] = value;
  }
  routedController.node = options.node;
  return routedController;
}

/**
 * Whether the create-database dialog should expose its charset/locale picker.
 *
 * For MySQL-family dialects this is a charset+collation control gated by
 * `canSetCreateDatabaseCharset`; for Informix-family dialects (GBase 8s) the same control is a
 * locale selector gated by `canSetCreateDatabaseLocale`. Both the routed controller and
 * `databaseDialogCapabilities()` must derive the flag from this single source, otherwise the two
 * paths drift and the picker silently disappears for locale-only dialects.
 */
export function routedCanSetCreateDatabaseCharset(canSetCreateDatabaseCharset: boolean, canSetCreateDatabaseLocale: boolean): boolean {
  return canSetCreateDatabaseCharset || canSetCreateDatabaseLocale;
}