diff options
author | Teddy Wing | 2022-03-13 13:16:11 +0100 |
---|---|---|
committer | Teddy Wing | 2022-03-13 13:16:11 +0100 |
commit | 1bdc5770b1ff4414dc97f82a412e7abb815361b0 (patch) | |
tree | 0bc7c15623b866d3157ee711d63a164fd4aa5d16 | |
parent | 8c02343737f4f980dc4e28f3892ed75d07527816 (diff) | |
download | yaqlite-1bdc5770b1ff4414dc97f82a412e7abb815361b0.tar.bz2 |
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.
-rw-r--r-- | src/main.rs | 30 |
1 files changed, 18 insertions, 12 deletions
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, + } => {}, + }; } |