mirror of
https://gitlab.com/fabinfra/fabaccess/bffh.git
synced 2024-11-11 01:53:23 +01:00
37 lines
957 B
Rust
37 lines
957 B
Rust
use std::sync::Arc;
|
|
use lmdb::{DatabaseFlags, Environment};
|
|
|
|
use rkyv::{Archive, Serialize, Deserialize};
|
|
|
|
use crate::db::{AllocAdapter, DB, RawDB};
|
|
use crate::users::UserRef;
|
|
|
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
#[derive(Archive, Serialize, Deserialize)]
|
|
pub struct Session {
|
|
userid: UserRef,
|
|
}
|
|
|
|
type Adapter = AllocAdapter<Session>;
|
|
pub struct SessionCache {
|
|
env: Arc<Environment>,
|
|
db: DB<Adapter>,
|
|
}
|
|
|
|
impl SessionCache {
|
|
pub unsafe fn new(env: Arc<Environment>, db: RawDB) -> Self {
|
|
let db = DB::new_unchecked(db);
|
|
Self { env, db }
|
|
}
|
|
|
|
pub unsafe fn open(env: Arc<Environment>) -> lmdb::Result<Self> {
|
|
let db = RawDB::open(&env, Some("sessions"))?;
|
|
Ok(Self::new(env, db))
|
|
}
|
|
|
|
pub unsafe fn create(env: Arc<Environment>) -> lmdb::Result<Self> {
|
|
let flags = DatabaseFlags::empty();
|
|
let db = RawDB::create(&env, Some("sessions"), flags)?;
|
|
Ok(Self::new(env, db))
|
|
}
|
|
} |