19 std::vector<uint8_t> bytes(
sizeof(
MyStruct));
20 std::memcpy(bytes.data(),
this,
sizeof(
MyStruct));
26 throw std::runtime_error(
"Invalid data size for MyStruct");
29 std::memcpy(&out, data,
sizeof(
MyStruct));
37 cfg.
pathname =
"any_value_table_example_db";
43 table.
set<
int>(
"retries", 3);
44 table.
set<std::string>(
"url",
"https://example.com");
47 auto retries = table.
get_or<
int>(
"retries", 1);
48#if __cplusplus >= 201703L
49 auto url = table.find<std::string>(
"url").value_or(
"none");
51 auto url_pair = table.
find_compat<std::string>(
"url");
52 std::string url = url_pair.first ? url_pair.second :
"none";
55 std::cout <<
"retries: " << retries <<
"\nurl: " << url <<
'\n';
57 for (
auto& key : table.
keys()) {
58 std::cout <<
"key: " << key <<
'\n';
61 std::cin.ignore(std::numeric_limits<std::streamsize>::max(),
'\n');
Table storing values of arbitrary type indexed by key.
int main()
Entry point demonstrating AnyValueTable.
Table storing values of arbitrary type associated with a key.
std::vector< KeyT > keys(MDBX_txn *txn=nullptr) const
List all keys stored in table.
void set(const KeyT &key, const T &value, MDBX_txn *txn=nullptr)
Set value for key, replacing existing value.
T get_or(const KeyT &key, T default_value, MDBX_txn *txn=nullptr) const
Get value or default if missing (C++11 mode).
std::pair< bool, T > find_compat(const KeyT &key, MDBX_txn *txn=nullptr) const
Find value by key.
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.
Demonstrates storing values of arbitrary types using AnyValueTable.
static MyStruct from_bytes(const void *data, size_t size)
std::vector< uint8_t > to_bytes() const