mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
cursor put (#54)
This commit is contained in:
@ -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,
|
||||
|
||||
Reference in New Issue
Block a user