Skip to content

Commit

Permalink
Read actual user query input in server
Browse files Browse the repository at this point in the history
  • Loading branch information
paolorechia committed Aug 7, 2024
1 parent d4e8952 commit 4a23b4b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
6 changes: 6 additions & 0 deletions steeldb-core/src/json_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,15 @@ impl TableJSON {
}
}

#[derive(Deserialize, Serialize, Debug)]
pub struct UserQueryJSON {
pub user_query: String,
}

#[derive(Deserialize, Serialize, Debug)]
pub struct QueryResultJSON {
pub table_result: Option<TableJSON>,
pub message: String,
pub status_code: u16
}

10 changes: 5 additions & 5 deletions steeldb-server/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use axum::{extract::State, http::StatusCode, routing::post, Json, Router};
use std::sync::{Arc, Mutex};
use steeldb::SteelDB;
use steeldb_core::json_result::{TableJSON, QueryResultJSON};
use steeldb_core::json_result::{TableJSON, QueryResultJSON, UserQueryJSON};
use steeldb_core::{ExecutionResult, SteelDBInterface};


#[tokio::main]
async fn main() {
let database = Arc::new(Mutex::new(SteelDB::new()));
Expand All @@ -19,18 +20,17 @@ async fn main() {
axum::serve(listener, app).await.unwrap();
}


async fn handle_query(
State(database): State<Arc<Mutex<SteelDB>>>,
// this argument tells axum to parse the request body
// as JSON into a `CreateUser` type
// Json(payload): Json<CreateUser>,
Json(payload): Json<UserQueryJSON>,
) -> (StatusCode, Json<QueryResultJSON>) {
// insert your application logic here
let db_mutex = Arc::clone(&database);
let result: ExecutionResult;
{
let mut db = db_mutex.lock().unwrap();
result = db.execute("select name;".to_owned());
result = db.execute(payload.user_query);
}
match result {
ExecutionResult::TableResult(table) => {
Expand Down

0 comments on commit 4a23b4b

Please sign in to comment.