mdbx++: add cursor::update_current() and cursor::reverse_current().

This commit is contained in:
Леонид Юрьев (Leonid Yuriev)
2025-11-17 14:51:22 +03:00
parent 0ec2758784
commit 77ac97879a
2 changed files with 25 additions and 0 deletions

View File

@@ -4487,6 +4487,11 @@ public:
inline void upsert(const slice &key, const slice &value);
inline slice upsert_reserve(const slice &key, size_t value_length);
/// \brief Updates value associated with a key at the current cursor position.
void update_current(const slice &value);
/// \brief Reserves and returns the space to storing a value associated with a key at the current cursor position.
slice reverse_current(size_t value_length);
inline void update(const slice &key, const slice &value);
inline bool try_update(const slice &key, const slice &value);
inline slice update_reserve(const slice &key, size_t value_length);

View File

@@ -1609,6 +1609,26 @@ __cold bool txn::rename_map(const ::std::string &old_name, const ::std::string &
//------------------------------------------------------------------------------
void cursor::update_current(const slice &value) {
default_buffer holder;
auto key = current().key;
if (error::boolean_or_throw(mdbx_is_dirty(handle_->txn, key.iov_base)))
key = holder.assign(key);
update(key, value);
}
slice cursor::reverse_current(size_t value_length) {
default_buffer holder;
auto key = current().key;
if (error::boolean_or_throw(mdbx_is_dirty(handle_->txn, key.iov_base)))
key = holder.assign(key);
return update_reserve(key, value_length);
}
//------------------------------------------------------------------------------
__cold ::std::ostream &operator<<(::std::ostream &out, const slice &it) {
out << "{";
if (!it.is_valid())