MDBX Containers
Loading...
Searching...
No Matches
config_initialized_table.cpp
Go to the documentation of this file.
1
5
7#include <iostream>
8#include <limits>
9
10int main() {
11 mdbxc::Config config;
12 config.pathname = "one_table_db";
13 config.max_dbs = 1;
14
15 mdbxc::KeyValueTable<int, std::string> table(config, "single_table");
16 table.clear();
17 table.insert_or_assign(1, "example");
18# if __cplusplus >= 201703L
19 auto val = table.find(1);
20 std::cout << "Found: " << (val ? *val : "not found") << std::endl;
21# else
22 auto val = table.find_compat(1);
23 std::cout << "Found: " << (val.first ? val.second : "not found") << std::endl;
24# endif
25
26 std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
27 std::cin.get();
28}
Declaration of the KeyValueTable class for managing key-value pairs in an MDBX database.
Parameters used by Connection to create the MDBX environment.
Definition Config.hpp:17
std::string pathname
Path to the database file or directory containing the database.
Definition Config.hpp:19
int64_t max_dbs
Maximum number of named databases (DBI) in the environment.
Definition Config.hpp:27
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.
std::pair< bool, ValueT > find(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.
int main()
Basic example using Config to initialize a table.