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.4 KB
Raw Blame
import { safeLocalStorageGet, safeLocalStorageSet } from "@/lib/backend/safeStorage";

export const MEILISEARCH_KEY_COLUMN_STORAGE_KEY = "dbx:meilisearch:key-columns:v1";
export const MEILISEARCH_KEY_COLUMN_KEYS = ["name", "key", "uid", "actions", "indexes", "expiresAt"] as const;
export type MeilisearchKeyColumnKey = (typeof MEILISEARCH_KEY_COLUMN_KEYS)[number];

function isKeyColumn(value: unknown): value is MeilisearchKeyColumnKey {
  return typeof value === "string" && MEILISEARCH_KEY_COLUMN_KEYS.includes(value as MeilisearchKeyColumnKey);
}

export function loadMeilisearchKeyColumns(): MeilisearchKeyColumnKey[] {
  try {
    const parsed = JSON.parse(safeLocalStorageGet(MEILISEARCH_KEY_COLUMN_STORAGE_KEY) || "null") as { visible?: unknown } | null;
    const visible = Array.isArray(parsed?.visible) ? parsed.visible.filter(isKeyColumn) : [];
    return visible.length ? MEILISEARCH_KEY_COLUMN_KEYS.filter((key) => visible.includes(key)) : [...MEILISEARCH_KEY_COLUMN_KEYS];
  } catch {
    return [...MEILISEARCH_KEY_COLUMN_KEYS];
  }
}

export function saveMeilisearchKeyColumns(visible: readonly MeilisearchKeyColumnKey[]): void {
  const normalized = MEILISEARCH_KEY_COLUMN_KEYS.filter((key) => visible.includes(key));
  safeLocalStorageSet(MEILISEARCH_KEY_COLUMN_STORAGE_KEY, JSON.stringify({ version: 1, visible: normalized.length ? normalized : [...MEILISEARCH_KEY_COLUMN_KEYS] }));
}