diff options
author | Teddy Wing | 2022-03-13 01:01:46 +0100 |
---|---|---|
committer | Teddy Wing | 2022-03-13 01:01:46 +0100 |
commit | e88bcdebd09d3644d8df1dd04386f121d83ef5da (patch) | |
tree | 20792571d2b4ee1a54d04bdde6f416d16ea38674 /src/yaml.rs | |
parent | 8dd59ee6fee0f023a75d4657ad07f6f09b14fc9c (diff) | |
download | yaqlite-e88bcdebd09d3644d8df1dd04386f121d83ef5da.tar.bz2 |
yaqlite::insert(): Add test
Check that the function inserts a record into the database based on a
YAML input.
Adjust the `extract()` function to take the table name as an argument.
Diffstat (limited to 'src/yaml.rs')
-rw-r--r-- | src/yaml.rs | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/yaml.rs b/src/yaml.rs index 532658a..2517d62 100644 --- a/src/yaml.rs +++ b/src/yaml.rs @@ -12,12 +12,13 @@ pub use sql::*; pub fn extract( doc: &mut yaml::Yaml, tx: &rusqlite::Transaction, + table_name: &str, table_columns: &HashMap<String, crate::sqlite::Zero>, ) { match doc { yaml::Yaml::Array(ref mut array) => { for yaml_value in array { - extract(yaml_value, tx, table_columns); + extract(yaml_value, tx, table_name, table_columns); } } yaml::Yaml::Hash(ref mut hash) => { @@ -35,11 +36,13 @@ pub fn extract( let mut stmt = tx.prepare( &format!( r#" - INSERT INTO "people" + INSERT INTO "{}" ({}) VALUES ({}); "#, + table_name, + // Wrap column names in quotes. hash.keys() .map(|k| format!(r#""{}""#, k.as_str().unwrap())) |