gmarche-rs/src/db.rs

32 lines
831 B
Rust
Raw Normal View History

2020-12-17 12:12:21 +01:00
use sled::Tree;
2020-10-26 23:43:18 +01:00
use std::path::Path;
2020-12-08 11:05:59 +01:00
const DB_DIR: &str = "db";
2020-10-26 23:43:18 +01:00
2022-02-25 15:41:50 +01:00
const DB_NAME_AD: &str = "ad";
const DB_NAME_AD_BY_GROUP: &str = "ad_by_group";
const DB_NAME_GROUP: &str = "group";
const DB_NAME_GROUP_BY_GROUP: &str = "group_by_group";
const DB_NAME_GROUP_BY_NAME: &str = "group_by_name";
2020-12-17 12:12:21 +01:00
#[derive(Clone)]
2020-10-26 23:43:18 +01:00
pub struct Dbs {
2022-02-25 15:41:50 +01:00
pub ad: Tree,
pub ad_by_group: Tree,
pub group: Tree,
pub group_by_group: Tree,
pub group_by_name: Tree,
2020-10-26 23:43:18 +01:00
}
pub fn load_dbs(path: &Path) -> Dbs {
let db = sled::open(path.join(DB_DIR)).expect("Cannot open db");
Dbs {
2022-02-25 15:41:50 +01:00
ad: db.open_tree(DB_NAME_AD).unwrap(),
ad_by_group: db.open_tree(DB_NAME_AD_BY_GROUP).unwrap(),
group: db.open_tree(DB_NAME_GROUP).unwrap(),
group_by_group: db.open_tree(DB_NAME_GROUP_BY_GROUP).unwrap(),
group_by_name: db.open_tree(DB_NAME_GROUP_BY_NAME).unwrap(),
}
2020-10-26 23:43:18 +01:00
}