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.6 KB
Raw Blame
import type { TextContentMatch, TextContentSearchOptions } from "../common/textContentSearch";
import type { JsonTreeSearchMatch, JsonTreeSearchPart } from "../common/jsonTreeSearch";

export interface RedisContentSearchRequest {
  text: string;
  query: string;
  options: TextContentSearchOptions;
  treeParts?: JsonTreeSearchPart[];
  replacement?: string;
  range?: TextContentMatch;
}
export interface RedisContentSearchResult {
  matches: (TextContentMatch | JsonTreeSearchMatch)[];
  changes?: { from: number; to: number; insert: string }[];
  error?: boolean;
}

/** Each job owns a worker, allowing cancellation even during regex backtracking. */
export function startRedisContentSearch(request: RedisContentSearchRequest) {
  let cancel = () => {};
  const result = new Promise<RedisContentSearchResult | null>((resolve) => {
    let worker: Worker | undefined;
    let timer: ReturnType<typeof setTimeout> | undefined;
    const finish = (value: RedisContentSearchResult | null) => {
      clearTimeout(timer);
      worker?.terminate();
      resolve(value);
    };
    cancel = () => finish(null);
    try {
      worker = new Worker(new URL("./redisContentSearch.worker.ts", import.meta.url), { type: "module" });
      worker.onmessage = (event: MessageEvent<RedisContentSearchResult>) => finish(event.data);
      worker.onerror = () => finish({ matches: [], error: true });
      timer = setTimeout(() => finish({ matches: [], error: true }), 2000);
      worker.postMessage(request);
    } catch {
      finish({ matches: [], error: true });
    }
  });
  return { result, cancel: () => cancel() };
}