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。
TypeScript aicliclickhousedatabasedatabase-clientdatabase-managementdockerguimcpmongodbmysqlpostgresqlredisrustsql-serversqlitetaurivue
import { describe, expect, it } from "vitest";
import { buildDatabaseTreeNodes } from "@/lib/database/databaseTree";
import { spannerDisplayDatabase } from "@/lib/connection/spannerResourcePath";
import type { DatabaseInfo } from "@/types/database";
const SPANNER_PATH = "projects/test-project/instances/test-instance/databases/gsqldb";
function databases(...names: string[]): DatabaseInfo[] {
return names.map((name) => ({ name }) as DatabaseInfo);
}
describe("buildDatabaseTreeNodes", () => {
it("labels nodes with the reported name when no displayLabel is given", () => {
const [node] = buildDatabaseTreeNodes("conn-1", databases("analytics"));
expect(node.label).toBe("analytics");
expect(node.database).toBe("analytics");
expect(node.id).toBe("conn-1:analytics");
});
it("carries database compatibility mode into database nodes", () => {
const [node] = buildDatabaseTreeNodes("conn-1", [{ name: "oracle_mode", compatibility_mode: "A" }]);
expect(node.compatibilityMode).toBe("A");
});
it("shortens the Cloud Spanner label but keeps the resource path as the node identity", () => {
const [node] = buildDatabaseTreeNodes("conn-1", databases(SPANNER_PATH), { displayLabel: spannerDisplayDatabase });
// Visible text is the database id only — a 60-char resource path would be
// truncated to `projects/test-proj…` in a narrow sidebar.
expect(node.label).toBe("gsqldb");
// Identity must stay the full path: it round-trips to the agent as
// ConnectParams.database, and the short name would break URL building.
expect(node.database).toBe(SPANNER_PATH);
expect(node.id).toBe(`conn-1:${SPANNER_PATH}`);
});
it("falls back to the reported name when displayLabel yields nothing", () => {
const [node] = buildDatabaseTreeNodes("conn-1", databases("analytics"), { displayLabel: () => "" });
expect(node.label).toBe("analytics");
});
it("leaves every other database type untouched when a displayLabel is absent", () => {
const nodes = buildDatabaseTreeNodes("conn-1", databases("beta", "alpha"));
expect(nodes.map((node) => node.label)).toEqual(["alpha", "beta"]);
});
});