diff options
| -rw-r--r-- | Cargo.lock | 56 | ||||
| -rw-r--r-- | Cargo.toml | 1 | ||||
| -rw-r--r-- | src/lib.rs | 2 | ||||
| -rw-r--r-- | src/sqlite.rs | 18 | 
4 files changed, 71 insertions, 6 deletions
| @@ -107,6 +107,24 @@ source = "registry+https://github.com/rust-lang/crates.io-index"  checksum = "58893f751c9b0412871a09abd62ecd2a00298c6c83befa223ef98c52aef40cbe"  [[package]] +name = "proc-macro2" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7342d5883fbccae1cc37a2353b09c87c9b0f3afd73f5fb9bba687a1f733b029" +dependencies = [ + "unicode-xid", +] + +[[package]] +name = "quote" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "864d3e96a899863136fc6e99f3d7cae289dafe43bf2c5ac19b70df7210c0a145" +dependencies = [ + "proc-macro2", +] + +[[package]]  name = "rusqlite"  version = "0.27.0"  source = "registry+https://github.com/rust-lang/crates.io-index" @@ -128,6 +146,43 @@ source = "registry+https://github.com/rust-lang/crates.io-index"  checksum = "f2dd574626839106c320a323308629dcb1acfc96e32a8cba364ddc61ac23ee83"  [[package]] +name = "syn" +version = "1.0.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a65b3f4ffa0092e9887669db0eae07941f023991ab58ea44da8fe8e2d511c6b" +dependencies = [ + "proc-macro2", + "quote", + "unicode-xid", +] + +[[package]] +name = "thiserror" +version = "1.0.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "854babe52e4df1653706b98fcfc05843010039b406875930a70e4d9644e5c417" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa32fd3f627f367fe16f893e2597ae3c05020f8bba2666a4e6ea73d377e5714b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "unicode-xid" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" + +[[package]]  name = "vcpkg"  version = "0.2.15"  source = "registry+https://github.com/rust-lang/crates.io-index" @@ -159,5 +214,6 @@ name = "yaqlite"  version = "0.0.1"  dependencies = [   "rusqlite", + "thiserror",   "yaml-rust",  ] @@ -5,4 +5,5 @@ edition = "2021"  [dependencies]  rusqlite = "0.27.0" +thiserror = "1.0.30"  yaml-rust = "0.4.5" @@ -7,7 +7,7 @@ pub fn insert(      table_name: &str,      data: &mut [yaml_rust::Yaml],  ) { -    let table_columns = crate::sqlite::get_column_names(&dbconn, table_name); +    let table_columns = crate::sqlite::get_column_names(&dbconn, table_name).unwrap();      for mut doc in data {          let tx = dbconn.transaction().unwrap(); diff --git a/src/sqlite.rs b/src/sqlite.rs index bb2c5bb..1e3aeec 100644 --- a/src/sqlite.rs +++ b/src/sqlite.rs @@ -1,8 +1,16 @@  use rusqlite; +use thiserror;  use std::collections::HashMap; +#[derive(thiserror::Error, Debug)] +pub enum SqliteError { +    #[error("SQL error")] +    Sqlite(#[from] rusqlite::Error), +} + +  /// Get the fundamental SQLite datatype for a given type name.  ///  /// Use the SQLite rules for type affinity described in: @@ -43,7 +51,7 @@ pub struct Zero;  pub fn get_column_names(      dbconn: &rusqlite::Connection,      table_name: &str, -) -> HashMap<String, Zero> { +) -> Result<HashMap<String, Zero>, SqliteError> {      let mut column_names = HashMap::new();      let mut stmt = dbconn.prepare( @@ -54,18 +62,18 @@ pub fn get_column_names(              "#,              table_name,          ), -    ).unwrap(); +    )?;      let rows = stmt.query_map(          [],          |row| row.get(0), -    ).unwrap(); +    )?;      for row_result in rows { -        let row = row_result.unwrap(); +        let row = row_result?;          column_names.insert(row, Zero{});      } -    column_names +    Ok(column_names)  } | 
