From 13ff6a600c42960cc60111ba1a7c661aa6aef334 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Wed, 9 Mar 2022 00:32:01 +0100 Subject: Idea for inserting values from YAML into SQLite table Need to figure out how to insert `table_columns.len()` values. --- src/main.rs | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index ca815fd..0fc81bb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,7 +16,11 @@ fn main() { let yaml_data = yaml::YamlLoader::load_from_str(&text_data).unwrap(); for doc in &yaml_data { - yaml_extract(&doc, &table_columns); + let tx = dbconn.transaction().unwrap(); + + yaml_extract(&doc, &tx, &table_columns); + + tx.commit().unwrap(); } dbg!(yaml_data); @@ -24,7 +28,11 @@ fn main() { dbconn.close().unwrap(); } -fn yaml_extract(doc: &yaml::Yaml, table_columns: &HashMap) { +fn yaml_extract( + doc: &yaml::Yaml, + tx: &rusqlite::Transaction, + table_columns: &HashMap, +) { match doc { yaml::Yaml::Array(ref array) => { for yaml_value in array { @@ -43,6 +51,16 @@ fn yaml_extract(doc: &yaml::Yaml, table_columns: &HashMap) { dbg!(k, v); } } + + tx.execute( + r#" + INSERT INTO "people" + () + VALUES + (); + "#, + [] + ).unwrap(); } _ => {} } -- cgit v1.2.3