From 13e784cf7a28f3d743d16b0a9b5ac6b8c5e10861 Mon Sep 17 00:00:00 2001 From: Gregor Reitzenstein Date: Tue, 15 Sep 2020 14:48:59 +0200 Subject: [PATCH] Simple machine lmdb interface --- src/machine.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/machine.rs b/src/machine.rs index 4f0dd1f..2cc1029 100644 --- a/src/machine.rs +++ b/src/machine.rs @@ -16,6 +16,8 @@ use capnp::Error; use uuid::Uuid; +use lmdb::{Transaction, RwTransaction}; + /// Status of a Machine #[derive(PartialEq, Eq, Debug, Serialize, Deserialize)] pub enum Status { @@ -167,10 +169,10 @@ impl MachineDB { Self { db } } - pub fn get_machine(&self, txn: &T, machine_id: MachineIdentifier) + pub fn get_machine(&self, txn: &T, uuid: Uuid) -> Result> { - match txn.get(self.db, &machine_id.to_ne_bytes()) { + match txn.get(self.db, &uuid.as_bytes()) { Ok(bytes) => { Ok(Some(flexbuffers::from_slice(bytes)?)) }, @@ -178,6 +180,15 @@ impl MachineDB { Err(e) => { Err(e.into()) }, } } + + pub fn put_machine( &self, txn: &mut RwTransaction, uuid: Uuid, machine: Machine) + -> Result<()> + { + let bytes = flexbuffers::to_vec(machine)?; + txn.put(self.db, &uuid.as_bytes(), &bytes, lmdb::WriteFlags::empty())?; + + Ok(()) + } } pub async fn init(log: Logger, config: &Settings) -> Result {