loading inner collections

This commit is contained in:
2026-08-14 11:17:22 +03:00
parent 4d0788e0f5
commit 17e06256c1
4 changed files with 184 additions and 15 deletions
+48
View File
@@ -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
}
+1
View File
@@ -6,3 +6,4 @@ pub(crate) mod sqlite;
pub(crate) mod voice;
pub(crate) mod words;
pub(crate) mod web_api;
pub(crate) mod import;