feat: add execute-script route and handler for executing SQL scripts

This commit is contained in:
t8y2 2026-05-05 03:22:26 +08:00
parent 41bceffc0e
commit 794c5375c7
3 changed files with 20 additions and 1 deletions

View File

@ -83,6 +83,7 @@ async fn main() {
.route("/query/execute", post(routes::query::execute_query))
.route("/query/execute-multi", post(routes::query::execute_multi))
.route("/query/execute-batch", post(routes::query::execute_batch))
.route("/query/execute-script", post(routes::query::execute_script))
.route("/query/cancel", post(routes::query::cancel_query))
// Redis
.route("/redis/list-databases", post(routes::redis::list_databases))

View File

@ -103,3 +103,20 @@ pub async fn cancel_query(
let cancelled = state.app.running_queries.cancel(&req.execution_id);
Json(serde_json::json!({ "cancelled": cancelled }))
}
pub async fn execute_script(
State(state): State<Arc<WebState>>,
Json(req): Json<ExecuteQueryRequest>,
) -> Result<Json<serde_json::Value>, AppError> {
let statements = dbx_core::sql::split_sql_statements(&req.sql);
let result = dbx_core::query::execute_statements(
&state.app,
&req.connection_id,
&req.database,
&statements,
)
.await
.map_err(AppError)?;
Ok(Json(serde_json::to_value(result).map_err(|e| AppError(e.to_string()))?))
}

View File

@ -942,7 +942,7 @@ const downloadProgress = ref(0);
const updateReady = ref(false);
async function downloadAndInstallUpdate() {
if (isDownloadingUpdate.value) return;
if (!isTauriRuntime() || isDownloadingUpdate.value) return;
isDownloadingUpdate.value = true;
downloadProgress.value = 0;
try {
@ -970,6 +970,7 @@ async function downloadAndInstallUpdate() {
}
async function restartApp() {
if (!isTauriRuntime()) return;
const { relaunch } = await import("@tauri-apps/plugin-process");
await relaunch();
}