From b067fb36e4bdfe2b96fe6a0f3c7a6e47f323f5c6 Mon Sep 17 00:00:00 2001 From: Joseph Ferano Date: Wed, 14 Nov 2018 09:54:54 -0400 Subject: [PATCH] Filled out add_data_node and started test module --- src/bin/meta_data.rs | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/src/bin/meta_data.rs b/src/bin/meta_data.rs index 82a501d..a321fca 100644 --- a/src/bin/meta_data.rs +++ b/src/bin/meta_data.rs @@ -9,14 +9,25 @@ fn main() { let conn = Connection::open("dfs.db").unwrap(); } - -fn connect(conn : Connection) { +#[derive(Debug)] +struct Dnode { + id : i32, + address : String, + port : i32, } -fn close(conn : Connection) { -} - -fn add_data_node(conn : Connection, address : String, port : usize) { +fn add_data_node(conn : &Connection, address : &str, port : i32) { + let dn = Dnode { + id : 0, + address : address.to_string(), + port, + }; + match conn.execute( + "INSERT INTO dnode (address, port) VALUES (?1, ?2)", + &[&dn.address as &ToSql, &dn.port]) { + Ok(n) => println!("{} rows updated", n), + Err(e) => println!("INSERT error: {}", e) + } } fn check_node(conn : Connection, address : String, port : usize) { @@ -40,3 +51,12 @@ fn add_block_to_inode(conn : Connection, fname : String, blocks : usize) { fn get_file_inode(conn : Connection, fname : String) { } +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn inserts_dnode() { + } + +}