feat(export): support database setup and batch SQL scripts

This commit is contained in:
二丫讲梵 authored and GitHub committed 2026-07-24 23:52:10 +08:00
1 parent 3d1601c807
commit 9cfee7f497
21 files changed
+622 -235

No files matched your search

+1
View File
@@ -310,6 +310,7 @@ export const listSshConfigHosts = forward("listSshConfigHosts");
// SQL File Execution
export const previewSqlFile = forward("previewSqlFile");
export const executeSqlFile = forward("executeSqlFile");
export const executeSqlFiles = forward("executeSqlFiles");
export const cancelSqlFileExecution = forward("cancelSqlFileExecution");
export const listenSqlFileProgress = forward("listenSqlFileProgress");
export const pendingOpenSqlFiles = forward("pendingOpenSqlFiles");
+4
View File
@@ -1495,6 +1495,10 @@ export async function executeSqlFile(request: SqlFileRequest): Promise<void> {
return post("/api/sql-file/execute", { request });
}
export async function executeSqlFiles(request: SqlFileRequest, filePaths: string[]): Promise<void> {
return post("/api/sql-file/execute", { request, filePaths });
}
export async function cancelSqlFileExecution(executionId: string): Promise<boolean> {
return post("/api/sql-file/cancel", { executionId });
}
+6
View File
@@ -2204,6 +2204,7 @@ export interface SqlFilePreview {
sizeBytes: number;
preview: string;
canExecuteWithoutSelectedDatabase: boolean;
establishesDatabaseContext?: boolean;
}
export interface SqlFileProgress {
@@ -2226,6 +2227,10 @@ export async function executeSqlFile(request: SqlFileRequest): Promise<void> {
return invoke("execute_sql_file", { request });
}
export async function executeSqlFiles(request: SqlFileRequest, filePaths: string[]): Promise<void> {
return invoke("execute_sql_files", { request, filePaths });
}
export async function cancelSqlFileExecution(executionId: string): Promise<boolean> {
return invoke("cancel_sql_file_execution", { executionId });
}
@@ -2467,6 +2472,7 @@ export interface DatabaseExportRequest {
includeStructure: boolean;
includeData: boolean;
includeObjects: boolean;
includeCreateDatabase?: boolean;
dropTableIfExists?: boolean;
omitAutoIncrement?: boolean;
failOnError?: boolean;
+27 -13
View File
@@ -1,17 +1,31 @@
import type { SqlFileProgress } from "@/lib/backend/tauri";
import { apiUrl } from "@/lib/common/webPath";
export function listenSqlFileProgressById(executionId: string, handler: (progress: SqlFileProgress) => void): () => void {
const es = new EventSource(apiUrl(`/api/sql-file/progress/${executionId}`));
es.onmessage = (e) => {
const progress: SqlFileProgress = JSON.parse(e.data);
handler(progress);
if (progress.status === "done" || progress.status === "error" || progress.status === "cancelled") {
es.close();
}
};
es.onerror = () => {
es.close();
};
return () => es.close();
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);
}
};
});
}