aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTeddy Wing2022-03-18 20:52:29 +0100
committerTeddy Wing2022-03-18 20:52:29 +0100
commitbab9dffa1ec169965f21c99e84b47166c1247eb9 (patch)
tree81188246f10e7363cb4141050a7ea55d4add2f2c /src
parentfbcbc2be91feebe8ab362f179ad7c519a0196dc3 (diff)
downloadyaqlite-bab9dffa1ec169965f21c99e84b47166c1247eb9.tar.bz2
select(): Try building a Yaml hash mapping column names to values
Not quite what the `yaml_rust::Yaml` output should be, but getting closer.
Diffstat (limited to 'src')
-rw-r--r--src/select.rs20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/select.rs b/src/select.rs
index 045514e..5e67bc1 100644
--- a/src/select.rs
+++ b/src/select.rs
@@ -1,3 +1,6 @@
+use std::collections::HashMap;
+
+
pub fn select(
dbconn: &rusqlite::Connection,
table_name: &str,
@@ -19,16 +22,27 @@ pub fn select(
).unwrap();
let column_count = stmt.column_count();
+ let column_names: Vec<yaml_rust::Yaml> = stmt.column_names()
+ .iter()
+ .map(|col| yaml_rust::Yaml::String((*col).to_owned()))
+ .collect();
+ // dbg!(column_names);
let rows = stmt.query_map(
rusqlite::named_params! {
":pk": record_id,
},
|row| {
- let mut data: Vec<Yaml> = Vec::with_capacity(column_count);
+ // let mut data: Vec<Yaml> = Vec::with_capacity(column_count);
+ //
+ // for i in 0..column_count {
+ // data.push(row.get(i)?);
+ // }
+
+ let mut data: HashMap<&yaml_rust::Yaml, Yaml> = HashMap::new();
- for i in 0..column_count {
- data.push(row.get(i)?);
+ for (i, column) in column_names.iter().enumerate() {
+ data.insert(&column, row.get(i)?);
}
Ok(data)