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。

2.2 KB
Raw Blame
import { safeLocalStorageGet, safeLocalStorageSet } from "@/lib/backend/safeStorage";

function matchStorageKey(type: "match-confirms" | "match-ignores" | "match-rules", connectionId: string, database: string, schema: string): string {
  return ["dbx", "diagram", type, "v1", connectionId, database, schema].join(":");
}

export function loadMatchConfirms(connectionId: string, database: string, schema: string): string[] {
  const key = matchStorageKey("match-confirms", connectionId, database, schema);
  try {
    return JSON.parse(safeLocalStorageGet(key) || "[]");
  } catch {
    return [];
  }
}

export function saveMatchConfirms(ids: string[], connectionId: string, database: string, schema: string): void {
  const key = matchStorageKey("match-confirms", connectionId, database, schema);
  safeLocalStorageSet(key, JSON.stringify(ids));
}

export function loadMatchIgnores(connectionId: string, database: string, schema: string): string[] {
  const key = matchStorageKey("match-ignores", connectionId, database, schema);
  try {
    return JSON.parse(safeLocalStorageGet(key) || "[]");
  } catch {
    return [];
  }
}

export function saveMatchIgnores(ids: string[], connectionId: string, database: string, schema: string): void {
  const key = matchStorageKey("match-ignores", connectionId, database, schema);
  safeLocalStorageSet(key, JSON.stringify(ids));
}

export function loadMatchRules(connectionId: string, database: string, schema: string): MatchRule[] {
  const key = matchStorageKey("match-rules", connectionId, database, schema);
  try {
    return JSON.parse(safeLocalStorageGet(key) || "[]");
  } catch {
    return [];
  }
}

export function saveMatchRules(rules: MatchRule[], connectionId: string, database: string, schema: string): void {
  const key = matchStorageKey("match-rules", connectionId, database, schema);
  safeLocalStorageSet(key, JSON.stringify(rules));
}

export function isAutoMatchEnabled(): boolean {
  return safeLocalStorageGet("dbx:diagram:match-enabled") !== "false";
}

export function setAutoMatchEnabled(enabled: boolean): void {
  safeLocalStorageSet("dbx:diagram:match-enabled", String(enabled));
}

export interface MatchRule {
  id: string;
  name: string;
  pattern: string;
  enabled: boolean;
  priority: number;
}