Add delete methods

This commit is contained in:
Olivier 'reivilibre' 2022-03-24 19:35:31 +00:00
parent 1622d45c23
commit c19fb15e1c
2 changed files with 21 additions and 0 deletions

View File

@ -48,4 +48,11 @@ impl<K: ?Sized + ZeroCopyByteWrapper, V: ?Sized + ZeroCopyByteWrapper> RawTable<
)?;
Ok(())
}
/// Returns true if the key was present.
pub fn delete<'txn>(&self, txn: &Txn<'txn, RW>, k: impl AsRef<K>) -> anyhow::Result<bool> {
Ok(txn
.mdbx_txn
.del(self.borrow_mdbx_db(), k.as_ref().as_byte_slice(), None)?)
}
}

View File

@ -45,4 +45,18 @@ impl<K: ByteWrapper, V: ByteWrapper> WrappedTable<K, V> {
self.raw.put(txn, k_bytes, v_bytes)?;
Ok(())
}
/// Returns true if the key was present.
pub fn delete<'txn>(
&self,
txn: &Txn<'txn, RW>,
k: impl AsRef<K::Item>,
) -> anyhow::Result<bool> {
let k_bytes = self
.k_wrapper
.dump_to_db_bytes(k.as_ref())
.context("whilst converting key to bytes")?;
self.raw.delete(txn, k_bytes)
}
}