loading inner collections
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
use rusqlite::Connection;
|
||||
use serde_json::Value;
|
||||
use std::collections::HashMap;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct ImportData(Vec<ImportGroup>);
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct ImportGroup {
|
||||
id: u64,
|
||||
name: String,
|
||||
fields: Vec<String>,
|
||||
mapping: HashMap<String, String>,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct ImportNote {
|
||||
name: String,
|
||||
tags: String,
|
||||
fields: Vec<String>,
|
||||
}
|
||||
|
||||
pub fn load_groups(connection: &Connection) -> ImportData {
|
||||
let json_models: String = connection
|
||||
.query_one("select models from col", (), |row| row.get(0))
|
||||
.unwrap();
|
||||
let raw: Value = serde_json::from_str(json_models.as_str()).unwrap();
|
||||
let sets = raw.as_object().unwrap();
|
||||
let mut total_data = ImportData(vec![]);
|
||||
|
||||
for (_, collection) in sets {
|
||||
let fields = collection["flds"]
|
||||
.as_array()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.map(|x| x["name"].as_str().unwrap().to_string())
|
||||
.collect();
|
||||
let group = ImportGroup {
|
||||
id: collection["id"].as_u64().unwrap(),
|
||||
name: collection["name"].as_str().unwrap().to_string(),
|
||||
fields,
|
||||
mapping: Default::default(),
|
||||
};
|
||||
println!("{:?}", group);
|
||||
total_data.0.push(group);
|
||||
}
|
||||
total_data
|
||||
}
|
||||
Reference in New Issue
Block a user