cursor put (#54)

This commit is contained in:
Roman Krasiuk
2022-10-12 18:16:59 +03:00
committed by GitHub
parent 111c13f12f
commit 08d8a7f030

View File

@ -5,7 +5,7 @@ use crate::{
kv::{Decode, DupSort, Encode, Table},
utils::*,
};
use libmdbx::{self, TransactionKind};
use libmdbx::{self, TransactionKind, WriteFlags, RW};
/// Alias type for a `(key, value)` result coming from a cursor.
pub type PairResult<T> = Result<Option<(<T as Table>::Key, <T as Table>::Value)>, KVError>;
@ -108,6 +108,15 @@ impl<'tx, K: TransactionKind, T: Table> Cursor<'tx, K, T> {
}
}
impl<'tx, T: Table> Cursor<'tx, RW, T> {
/// Inserts a `(key, value)` to the database. Repositions the cursor to the new item
pub fn put(&mut self, k: T::Key, v: T::Value, f: Option<WriteFlags>) -> Result<(), KVError> {
self.inner
.put(k.encode().as_ref(), v.encode().as_ref(), f.unwrap_or_default())
.map_err(KVError::Put)
}
}
impl<'txn, K, T> Cursor<'txn, K, T>
where
K: TransactionKind,