mirror of
https://github.com/isar/libmdbx.git
synced 2025-12-16 17:12:23 +08:00
mdbx++: add cursor::update_current() and cursor::reverse_current().
This commit is contained in:
5
mdbx.h++
5
mdbx.h++
@@ -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);
|
||||
|
||||
20
src/mdbx.c++
20
src/mdbx.c++
@@ -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())
|
||||
|
||||
Reference in New Issue
Block a user