diff --git a/crates/db/src/kv/cursor.rs b/crates/db/src/kv/cursor.rs index 8ed4f4d61..0aaf66b17 100644 --- a/crates/db/src/kv/cursor.rs +++ b/crates/db/src/kv/cursor.rs @@ -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 = Result::Key, ::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) -> 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,