Skip to content

Commit

Permalink
Implement correct JSON interface in server
Browse files Browse the repository at this point in the history
  • Loading branch information
paolorechia committed Jan 10, 2024
1 parent e0a8263 commit 3980d0d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 15 deletions.
7 changes: 0 additions & 7 deletions src/database/in_memory_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 6 additions & 3 deletions steeldb-core/src/json_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
}
2 changes: 0 additions & 2 deletions steeldb-core/src/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 7 additions & 3 deletions steeldb-server/src/main.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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()
Expand Down

0 comments on commit 3980d0d

Please sign in to comment.