From d6e9a6243f790c1669a687662ed312df044d006a Mon Sep 17 00:00:00 2001 From: Darren Baldwin Date: Fri, 18 Oct 2024 12:56:32 -0400 Subject: [PATCH] rm endpoint in dataplane --- dataplane-webserver/src/routes/sql.rs | 86 --------------------------- 1 file changed, 86 deletions(-) delete mode 100644 dataplane-webserver/src/routes/sql.rs diff --git a/dataplane-webserver/src/routes/sql.rs b/dataplane-webserver/src/routes/sql.rs deleted file mode 100644 index 88749d081..000000000 --- a/dataplane-webserver/src/routes/sql.rs +++ /dev/null @@ -1,86 +0,0 @@ -use actix_web::{post, web, HttpResponse}; -use serde::{Deserialize, Serialize}; -use serde_json::{json, Map as JsonMap, Value as JsonValue}; -use sqlx::Column; -use sqlx::Pool; -use sqlx::Postgres; -use sqlx::Row; - -#[derive(Deserialize)] -struct SqlRequest { - query: String, - params: Vec, -} - -#[derive(Serialize)] -struct ErrorResponse { - error: String, -} - -#[post("/sql")] -async fn sql_endpoint(pool: web::Data>, req: web::Json) -> HttpResponse { - let mut conn = match pool.acquire().await { - Ok(conn) => conn, - Err(e) => { - return HttpResponse::InternalServerError().json(ErrorResponse { - error: e.to_string(), - }) - } - }; - - let mut query = sqlx::query(&req.query); - - for param in &req.params { - query = query.bind(param); - } - - let result = query.fetch_all(&mut *conn).await; - - match result { - Ok(rows) => { - // Extract column names - let columns: Vec = rows[0] - .columns() - .iter() - .map(|col| col.name().to_string()) - .collect(); - - // Convert rows to array of arrays - let array_data: Vec> = rows - .iter() - .map(|row| { - columns - .iter() - .map(|col| { - let value: JsonValue = - row.try_get(col.as_str()).unwrap_or(JsonValue::Null); - value - }) - .collect() - }) - .collect(); - - let raw_data: Vec> = rows - .iter() - .map(|row| { - columns - .iter() - .filter_map(|col| { - let value: JsonValue = - row.try_get(col.as_str()).unwrap_or(JsonValue::Null); - Some((col.clone(), value)) - }) - .collect() - }) - .collect(); - - HttpResponse::Ok().json(json!({ - "raw": raw_data, - "cleaned": array_data, - })) - } - Err(e) => HttpResponse::InternalServerError().json(ErrorResponse { - error: e.to_string(), - }), - } -}