only one method to execute queries is needed apparently

This commit is contained in:
2026-05-04 14:08:13 -07:00
parent 2a1cc97fe2
commit 673d51d706
3 changed files with 2 additions and 20 deletions

View File

@ -1,6 +1,6 @@
use crate::data::{Game, Player, Team};
use actix_web::{Error, error, web};
use rusqlite::{Row, params};
use rusqlite::Row;
use serde_json::{Map, Value};
use std::collections::HashMap;
@ -14,18 +14,6 @@ const GAMES_QUERY: &str =
const TEAMS_QUERY: &str =
"select game, team, min(color), group_concat(player) from teams group by game, team";
pub async fn execute_query(pool: &Pool, query: &str) -> Result<String, Error> {
let pool = pool.clone();
let conn = web::block(move || pool.get())
.await?
.map_err(error::ErrorInternalServerError)?;
match conn.execute(query, params![]) {
Ok(val) => println!("{val:?}"),
Err(er) => println!("error: {er:?}"),
}
Ok(String::from("success"))
}
pub async fn execute_stmt(pool: &Pool, query: &str) -> Result<String, Error> {
let pool = pool.clone();
let conn = web::block(move || pool.get())

View File

@ -65,7 +65,6 @@ struct GamesActor {
#[derive(Deserialize, Debug)]
struct QueryForm {
query: String,
is_read: bool,
}
impl Actor for GamesActor {
@ -181,11 +180,7 @@ async fn list_of_games(games: web::Data<Arc<Mutex<Vec<Game>>>>) -> impl Responde
#[post("/admin/query")]
async fn admin_query(pool: web::Data<Pool>, form: web::Form<QueryForm>) -> impl Responder {
let res: String;
if form.is_read {
res = db::execute_stmt(&pool, &form.query).await.unwrap();
} else {
res = db::execute_query(&pool, &form.query).await.unwrap();
}
res = db::execute_stmt(&pool, &form.query).await.unwrap();
HttpResponse::Ok()
.content_type("application/json")
.body(res)

View File

@ -76,7 +76,6 @@
method: "POST",
body: new URLSearchParams({
'query': document.getElementById("query").value,
'is_read': true,
})
})
.then(res => {