fluxen 1.1.1
Single-header embedded key-value store for C++20
Loading...
Searching...
No Matches
fluxen::Tx Class Reference

A staged batch of write operations, used inside DB::transaction(). More...

#include <fluxen.hpp>

Public Member Functions

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.

Friends

class DB

Detailed Description

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()

Member Function Documentation

◆ put() [1/2]

void fluxen::Tx::put ( std::string_view key,
std::string_view value )
inline

Stage a string value to be written.

Parameters
keyThe key to write (max 255 bytes).
valueThe string value to store.
Exceptions
std::runtime_errorIf 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
TAny trivially copyable type: int, float, struct, etc.
Parameters
keyThe key to write (max 255 bytes).
valueThe value to store. Stored as raw bytes via memcpy.
Exceptions
std::runtime_errorIf 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
keyThe key to delete.
Exceptions
std::runtime_errorIf the key is empty or longer than 255 bytes.

The documentation for this class was generated from the following file: