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。

1002 B
Raw Blame
import type { SqlFileProgress } from "@/lib/backend/tauri";
import { apiUrl } from "@/lib/common/webPath";

export function listenSqlFileProgressById(executionId: string, handler: (progress: SqlFileProgress) => void, onError?: (error: Error) => void): Promise<() => void> {
  return new Promise((resolve, reject) => {
    const es = new EventSource(apiUrl(`/api/sql-file/progress/${executionId}`));
    let opened = false;
    const close = () => es.close();

    es.onopen = () => {
      opened = true;
      resolve(close);
    };
    es.onmessage = (e) => {
      const progress: SqlFileProgress = JSON.parse(e.data);
      handler(progress);
      if (progress.status === "done" || progress.status === "error" || progress.status === "cancelled") {
        close();
      }
    };
    es.onerror = () => {
      close();
      const error = new Error("SQL file progress connection failed");
      if (opened) {
        onError?.(error);
      } else {
        reject(error);
      }
    };
  });
}