aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/main.rs34
-rw-r--r--src/sqlite.rs29
2 files changed, 34 insertions, 29 deletions
diff --git a/src/main.rs b/src/main.rs
index 3a65e3c..91e9fb6 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,6 +1,9 @@
use rusqlite;
use yaml_rust::yaml;
+use std::collections::HashMap;
+
+
fn main() {
println!("Hello, world!");
@@ -8,7 +11,7 @@ fn main() {
let mut dbconn = rusqlite::Connection::open("./test.db").unwrap();
- let table_columns = get_column_names(&dbconn);
+ let table_columns = yaqlite::sqlite::get_column_names(&dbconn);
dbg!(&table_columns);
let text_data = std::fs::read_to_string("test2.yml").unwrap();
@@ -31,7 +34,7 @@ fn main() {
fn yaml_extract(
doc: &mut yaml::Yaml,
tx: &rusqlite::Transaction,
- table_columns: &HashMap<String, Zero>,
+ table_columns: &HashMap<String, yaqlite::sqlite::Zero>,
) {
match doc {
yaml::Yaml::Array(ref mut array) => {
@@ -101,30 +104,3 @@ fn yaml_extract(
_ => {}
}
}
-
-#[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("people");
- "#).unwrap();
-
- let rows = stmt.query_map(
- [],
- |row| row.get(0),
- ).unwrap();
-
- for row_result in rows {
- let row = row_result.unwrap();
-
- column_names.insert(row, Zero{});
- }
-
- column_names
-}
diff --git a/src/sqlite.rs b/src/sqlite.rs
index 8094398..15c813c 100644
--- a/src/sqlite.rs
+++ b/src/sqlite.rs
@@ -1,5 +1,7 @@
use rusqlite;
+use std::collections::HashMap;
+
/// Get the fundamental SQLite datatype for a given type name.
///
@@ -32,3 +34,30 @@ pub fn affinity(type_name: &str) -> rusqlite::types::Type {
Type::Text
}
+
+
+#[derive(Debug)]
+pub struct Zero {}
+
+
+pub 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("people");
+ "#).unwrap();
+
+ let rows = stmt.query_map(
+ [],
+ |row| row.get(0),
+ ).unwrap();
+
+ for row_result in rows {
+ let row = row_result.unwrap();
+
+ column_names.insert(row, Zero{});
+ }
+
+ column_names
+}