/* 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 log::info; use serde::{Deserialize, Serialize}; use std::path::Path; use typed_sled::Tree; pub struct Database { pub db: sled::Db, pub users: Tree, pub invites: Tree, } #[derive(Debug, Clone, Serialize, Deserialize)] pub struct User { pub name: String, pub display_name: String, pub password: Vec, pub admin: bool, } 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 { users: Tree::open(&db, "users"), invites: Tree::open(&db, "invites"), db, }); info!("ready"); r } }