15 std::vector<uint8_t> bytes(
sizeof(
MyData));
16 std::memcpy(bytes.data(),
this,
sizeof(
MyData));
21 if (size !=
sizeof(
MyData))
22 throw std::runtime_error(
"Invalid data size for MyData");
24 std::memcpy(&out, data,
sizeof(
MyData));
31 config.
pathname =
"custom_struct_db";
38# if __cplusplus >= 201703L
39 auto result = table.find(42);
41 std::cout <<
"id: " << result->id <<
", value: " << result->value << std::endl;
45 std::cout <<
"id: " << result.second.id <<
", value: " << result.second.value << std::endl;
Declaration of the KeyValueTable class for managing key-value pairs in an MDBX database.
Parameters used by Connection to create the MDBX environment.
std::string pathname
Path to the database file or directory containing the database.
int64_t max_dbs
Maximum number of named databases (DBI) in the environment.
static std::shared_ptr< Connection > create(const Config &config)
Creates and connects a new shared Connection instance.
Template class for managing key-value pairs in an MDBX database.
void insert_or_assign(const KeyT &key, const ValueT &value, MDBX_txn *txn=nullptr)
Inserts or replaces key-value pair.
std::pair< bool, ValueT > find_compat(const KeyT &key, MDBX_txn *txn=nullptr) const
Finds value by key.
void clear(MDBX_txn *txn=nullptr)
Clears all key-value pairs from the database.
Storing a custom struct with to_bytes/from_bytes.
static MyData from_bytes(const void *data, size_t size)
std::vector< uint8_t > to_bytes() const