A staged batch of write operations, used inside DB::transaction().
More...
#include <fluxen.hpp>
|
| void | put (std::string_view key, std::string_view value) |
| | Stage a string value to be written.
|
template<typename T>
requires (std::is_trivially_copyable_v<T> && !std::is_convertible_v<T, std::string_view>) |
| void | put (std::string_view key, const T &value) |
| | Stage a trivially copyable value to be written.
|
| void | remove (std::string_view key) |
| | Stage a key deletion.
|
A staged batch of write operations, used inside DB::transaction().
A Tx is constructed by DB::transaction() and passed to the callback. Operations staged on it are only applied to the database if the callback returns fluxen::commit. They are discarded on fluxen::rollback or if the callback throws.
- Note
- Do not construct a
Tx directly, use DB::transaction().
- See also
- DB::transaction()
◆ put() [1/2]
| void fluxen::Tx::put |
( |
std::string_view | key, |
|
|
std::string_view | value ) |
|
inline |
Stage a string value to be written.
- Parameters
-
| key | The key to write (max 255 bytes). |
| value | The string value to store. |
- Exceptions
-
| std::runtime_error | If the key is empty or longer than 255 bytes. |
◆ put() [2/2]
template<typename T>
requires (std::is_trivially_copyable_v<T> && !std::is_convertible_v<T, std::string_view>)
| void fluxen::Tx::put |
( |
std::string_view | key, |
|
|
const T & | value ) |
|
inline |
Stage a trivially copyable value to be written.
Accepts any type that satisfies std::is_trivially_copyable, except types convertible to std::string_view (those go through the string overload above).
- Template Parameters
-
| T | Any trivially copyable type: int, float, struct, etc. |
- Parameters
-
| key | The key to write (max 255 bytes). |
| value | The value to store. Stored as raw bytes via memcpy. |
- Exceptions
-
| std::runtime_error | If the key is empty or longer than 255 bytes. |
- Example
struct Point { float x, y; };
tx.put("origin", Point{0.0f, 0.0f});
tx.put("count", int32_t{42});
◆ remove()
| void fluxen::Tx::remove |
( |
std::string_view | key | ) |
|
|
inline |
Stage a key deletion.
If the key does not exist in the database, this is a no-op when the transaction is committed.
- Parameters
-
- Exceptions
-
| std::runtime_error | If the key is empty or longer than 255 bytes. |
The documentation for this class was generated from the following file: