Move MachineDB into LMDB

This commit is contained in:
Gregor Reitzenstein 2020-09-15 14:41:50 +02:00
parent 76ccddb4cb
commit 4fde079986

View File

@ -158,7 +158,27 @@ impl Machine {
}
}
pub type MachineDB = HashMap<Uuid, Machine>;
struct MachineDB {
db: lmdb::Database,
}
impl MachineDB {
pub fn new(db: lmdb::Database) -> Self {
Self { db }
}
pub fn get_machine<T: Transaction>(&self, txn: &T, machine_id: MachineIdentifier)
-> Result<Option<Machine>>
{
match txn.get(self.db, &machine_id.to_ne_bytes()) {
Ok(bytes) => {
Ok(Some(flexbuffers::from_slice(bytes)?))
},
Err(lmdb::Error::NotFound) => { Ok(None) },
Err(e) => { Err(e.into()) },
}
}
}
pub async fn init(log: Logger, config: &Settings) -> Result<MachinesProvider> {
unimplemented!()