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。

911 B
Raw Blame
/**
 * Query results can contain duplicate column labels, e.g.
 * `SELECT a.name, b.name, c.name ...` (#12452). The grid, sorting, filtering
 * and copy paths all look columns up by name, so duplicates make them address
 * the first match only.
 *
 * Rename duplicates once at the result boundary, Navicat-style:
 * `name, name, name` -> `name, name_1, name_2`. Existing names are never
 * reused, so a result that already contains `name_1` stays unambiguous.
 */
export function dedupeResultColumnNames(columns: readonly string[]): string[] {
  const used = new Set<string>();
  return columns.map((column) => {
    if (!used.has(column)) {
      used.add(column);
      return column;
    }
    let suffix = 1;
    let candidate = `${column}_${suffix}`;
    while (used.has(candidate)) {
      suffix += 1;
      candidate = `${column}_${suffix}`;
    }
    used.add(candidate);
    return candidate;
  });
}