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 type { DatabaseType, QueryResult } from "@/types/database";
import { graphPropertyMatchesValue, type GraphEdge, type GraphNode, type GraphProperty } from "./graphResult";
import { applyGraphPropertyToResult, buildNebulaGraphExpand, buildNebulaGraphPropertyUpdate, graphPropertyMatchesValue as nebulaPropertyMatchesValue } from "./nebulaGraph";
import { applyNeo4jGraphPropertyToResult, buildNeo4jGraphExpand, buildNeo4jGraphPropertyUpdate } from "./neo4jGraph";

interface GraphAdapter {
  buildPropertyUpdate: (entity: GraphNode | GraphEdge, property: GraphProperty, value: string | boolean) => string;
  buildExpand: (node: GraphNode) => string;
  applyPropertyUpdate: (result: QueryResult, entity: GraphNode | GraphEdge, property: GraphProperty, updated: GraphProperty) => void;
  matchesPropertyValue: (property: GraphProperty, value: string | boolean) => boolean;
}

const adapters: Partial<Record<DatabaseType, GraphAdapter>> = {
  nebula: { buildPropertyUpdate: buildNebulaGraphPropertyUpdate, buildExpand: buildNebulaGraphExpand, applyPropertyUpdate: applyGraphPropertyToResult, matchesPropertyValue: nebulaPropertyMatchesValue },
  neo4j: { buildPropertyUpdate: buildNeo4jGraphPropertyUpdate, buildExpand: buildNeo4jGraphExpand, applyPropertyUpdate: applyNeo4jGraphPropertyToResult, matchesPropertyValue: graphPropertyMatchesValue },
};

export function graphAdapterForDatabase(type: DatabaseType | undefined): GraphAdapter | undefined {
  return type ? adapters[type] : undefined;
}