fabaccess-bffh/bffhd/db/mod.rs

57 lines
1.4 KiB
Rust
Raw Normal View History

2021-12-06 21:53:42 +01:00
use std::marker::PhantomData;
2021-10-07 16:44:01 +02:00
pub use lmdb::{
Environment,
DatabaseFlags,
WriteFlags,
EnvironmentFlags,
Transaction,
RoTransaction,
RwTransaction,
};
2022-03-15 20:00:43 +01:00
use rkyv::{Fallible, Serialize, ser::serializers::AllocSerializer, AlignedVec};
2021-10-07 16:44:01 +02:00
mod raw;
2021-11-26 21:01:43 +01:00
pub use raw::RawDB;
2021-10-07 16:44:01 +02:00
2021-10-19 11:16:24 +02:00
use lmdb::Error;
2021-10-20 20:56:47 +02:00
use rkyv::Deserialize;
2021-10-19 11:16:24 +02:00
use rkyv::ser::serializers::AlignedSerializer;
2022-03-15 20:00:43 +01:00
use crate::users::db::{User};
2021-10-20 18:37:50 +02:00
use std::collections::HashMap;
2022-03-15 16:27:41 +01:00
use std::fmt::{Display, Formatter};
2022-03-13 20:11:37 +01:00
use rkyv::Infallible;
2022-03-15 20:00:43 +01:00
use crate::resources::state::{State};
2021-10-20 18:37:50 +02:00
use std::iter::FromIterator;
2021-10-20 20:56:47 +02:00
use std::ops::Deref;
2022-03-13 20:11:37 +01:00
use crate::resources::search::ResourcesHandle;
2022-03-15 20:00:43 +01:00
2022-03-15 19:56:41 +01:00
use crate::Users;
2021-10-20 20:56:47 +02:00
#[derive(Debug, serde::Serialize)]
2021-10-20 18:37:50 +02:00
pub struct Dump {
users: HashMap<String, User>,
2022-03-13 20:11:37 +01:00
states: HashMap<String, State>,
2021-10-20 18:37:50 +02:00
}
impl Dump {
2022-03-15 19:56:41 +01:00
pub fn new(userdb: Users, resources: ResourcesHandle) -> Result<Self> {
let users = HashMap::from_iter(userdb.into_inner().get_all()?.into_iter());
2021-10-20 20:56:47 +02:00
let mut states = HashMap::new();
2022-03-13 20:11:37 +01:00
for resource in resources.list_all().into_iter() {
if let Some(output) = resource.get_raw_state() {
let output: State = Deserialize::<State, _>::deserialize(output.deref(), &mut Infallible).unwrap();
let old = states.insert(resource.get_id().to_string(), output);
assert!(old.is_none());
}
2021-10-20 20:56:47 +02:00
}
2022-03-15 19:56:41 +01:00
Ok(Self { users, states })
2021-10-20 18:37:50 +02:00
}
2021-10-18 11:27:42 +02:00
}