blob: cfdf0ab062e2f541bba5aaae3999c6dcc2c96e29 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
use rusqlite;
use yaml_rust::yaml;
fn main() {
println!("Hello, world!");
// Get column names from SQLite
let dbconn = rusqlite::Connection::open("./test.db").unwrap();
let table_columns = get_column_names(&dbconn);
dbg!(table_columns);
let text_data = std::fs::read_to_string("test.yml").unwrap();
let yaml_data = yaml::YamlLoader::load_from_str(&text_data).unwrap();
for doc in &yaml_data {
yaml_extract(&doc);
}
dbg!(yaml_data);
dbconn.close().unwrap();
}
fn yaml_extract(doc: &yaml::Yaml) {
match doc {
yaml::Yaml::Array(ref array) => {
for yaml_value in array {
yaml_extract(yaml_value);
}
}
yaml::Yaml::Hash(ref hash) => {
// Begin transaction
for (k, v) in hash {
// TODO: Put k,v in a HashMap prepared for SQLite interfacing
dbg!(k, v);
// Each hash is a new record for SQLite insertion
// If key matches a column name, add it to the insert statement
}
}
_ => {}
}
}
#[derive(Debug)]
struct Zero {}
use std::collections::HashMap;
fn get_column_names(dbconn: &rusqlite::Connection) -> HashMap<String, Zero> {
let mut column_names = HashMap::new();
let mut stmt = dbconn.prepare(r#"
SELECT "name"
FROM pragma_table_info("test");
"#).unwrap();
let rows = stmt.query_map(
[],
|row| row.get(0),
).unwrap();
for row in rows {
column_names.insert(row.unwrap(), Zero{});
}
column_names
}
|