/* This file is part of jellything (https://codeberg.org/metamuffin/jellything) which is licensed under the GNU Affero General Public License (version 3); see /COPYING. Copyright (C) 2023 metamuffin */ use anyhow::Context; use jellycommon::{ user::{NodeUserData, User}, Node, }; use log::info; use std::{collections::HashMap, path::Path}; use typed_sled::Tree; pub use sled; pub use typed_sled; pub struct Database { pub db: sled::Db, pub user: Tree, pub user_node: Tree<(String, String), NodeUserData>, pub invite: Tree, pub node: Tree, } impl Database { pub fn open(path: &Path) -> Result { info!("opening database… (might take up to O(n) time)"); let db = sled::open(path).context("opening database")?; info!("creating trees"); let r = Ok(Self { user: Tree::open(&db, "user"), invite: Tree::open(&db, "invite"), node: Tree::open(&db, "node"), user_node: Tree::open(&db, "user_node"), db, }); info!("ready"); r } }