From 3980d0d039fc4e91c414967ccb658519654ac397 Mon Sep 17 00:00:00 2001 From: Paolo Rechia <paolorechia@gmail.com> Date: Wed, 10 Jan 2024 08:50:04 +0100 Subject: [PATCH] Implement correct JSON interface in server --- src/database/in_memory_table.rs | 7 ------- steeldb-core/src/json_result.rs | 9 ++++++--- steeldb-core/src/table.rs | 2 -- steeldb-server/src/main.rs | 10 +++++++--- 4 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/database/in_memory_table.rs b/src/database/in_memory_table.rs index c02a97a..f4da1eb 100644 --- a/src/database/in_memory_table.rs +++ b/src/database/in_memory_table.rs @@ -60,13 +60,6 @@ impl Table for InMemoryTable { fn get_select_columns(&self) -> &Vec<String> { return &self.select_columns; } - fn move_columns(self) -> HashMap<String, Vec<DataType>> { - return self.columns; - } - fn move_select_columns(self) -> Vec<String> { - return self.select_columns; - } - /// Saves the table to disk. fn save(&self, mode: SaveMode, format: FileFormat) -> Result<(), TableErrors> { let s = InMemoryTable::get_table_path(&self.name, &format); diff --git a/steeldb-core/src/json_result.rs b/steeldb-core/src/json_result.rs index 5451bdb..e1424eb 100644 --- a/steeldb-core/src/json_result.rs +++ b/steeldb-core/src/json_result.rs @@ -11,10 +11,13 @@ pub struct TableJSON { impl TableJSON { pub fn from_table(table: Box::<dyn Table>) -> TableJSON { + let table_name = table.get_table_name(); + let select_columns = table.get_select_columns().clone(); + let columns = table.get_columns().clone(); TableJSON { - table_name: table.get_table_name(), - columns: table.move_columns(), - select_columns: table.move_select_columns(), + table_name, + select_columns, + columns, } } } \ No newline at end of file diff --git a/steeldb-core/src/table.rs b/steeldb-core/src/table.rs index bc5d0f8..91073da 100644 --- a/steeldb-core/src/table.rs +++ b/steeldb-core/src/table.rs @@ -40,8 +40,6 @@ pub trait Table { fn get_table_name(&self) -> String; fn get_columns(&self) -> &HashMap<String, Vec<DataType>>; fn get_select_columns(&self) -> &Vec<String>; - fn move_columns(self) -> HashMap<String, Vec<DataType>>; - fn move_select_columns(self) -> Vec<String>; } use core::fmt::Debug; diff --git a/steeldb-server/src/main.rs b/steeldb-server/src/main.rs index b61a5aa..a918781 100644 --- a/steeldb-server/src/main.rs +++ b/steeldb-server/src/main.rs @@ -1,5 +1,7 @@ -use steeldb_core::json_result::HelloJSON; +use steeldb_core::json_result::TableJSON; +use steeldb::SteelDB; +use std::collections::HashMap; use std::convert::Infallible; use std::net::SocketAddr; @@ -12,8 +14,10 @@ use hyper_util::rt::TokioIo; use tokio::net::TcpListener; async fn hello(_: Request<hyper::body::Incoming>) -> Result<Response<Full<Bytes>>, Infallible> { - let hello_response = HelloJSON { - hello: "world!".to_owned(), + let hello_response = TableJSON { + table_name: "world!".to_owned(), + columns: HashMap::new(), + select_columns: Vec::new(), }; let desserialized = serde_json::to_string(&hello_response).unwrap(); let response = Response::builder()