From 1bdc5770b1ff4414dc97f82a412e7abb815361b0 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sun, 13 Mar 2022 13:16:11 +0100 Subject: main(): Move code to `insert` subcommand Change subcommand matcher to destructure the struct fields as I couldn't access the fields with dot notation before. --- src/main.rs | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index d12015a..1bc270e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -40,22 +40,28 @@ fn main() { // Get column names from SQLite match args.command { - a @ Command::Insert { .. } => { - dbg!(a.database); - } + Command::Insert { + database, + table_name, + input_file, + } => { + let mut dbconn = rusqlite::Connection::open(database).unwrap(); - a @ Command::Select { .. } => {} - }; - - let mut dbconn = rusqlite::Connection::open("./test.db").unwrap(); + let text_data = std::fs::read_to_string(input_file.unwrap()).unwrap(); - let text_data = std::fs::read_to_string("test2.yml").unwrap(); + let mut yaml_data = yaml::YamlLoader::load_from_str(&text_data).unwrap(); - let mut yaml_data = yaml::YamlLoader::load_from_str(&text_data).unwrap(); + yaqlite::insert(&mut dbconn, &table_name, &mut yaml_data).unwrap(); - yaqlite::insert(&mut dbconn, "people", &mut yaml_data).unwrap(); + dbg!(yaml_data); - dbg!(yaml_data); + dbconn.close().unwrap(); + }, - dbconn.close().unwrap(); + Command::Select { + database, + table_name, + record_id, + } => {}, + }; } -- cgit v1.2.3