19 table.insert_or_assign(1,
"one");
20 table.insert_or_assign(2,
"two");
23 bool inserted = table.insert(3,
"three");
24 std::cout <<
"Inserted key 3: " << inserted << std::endl;
26 inserted = table.insert(2,
"TWO");
27 std::cout <<
"Inserted key 2 again: " << inserted <<
" (should be false)" << std::endl;
30 std::cout <<
"Contains key 1: " << table.contains(1) << std::endl;
31 std::cout <<
"Contains key 4: " << table.contains(4) << std::endl;
35 std::cout <<
"table[4]: " <<
static_cast<std::string
>(table[4]) << std::endl;
38 std::map<int, std::string> snapshot = table();
39 std::cout <<
"Snapshot:\n";
40 for (
const auto& [k, v] : snapshot)
41 std::cout << k <<
": " << v << std::endl;
44 std::unordered_map<int, std::string> temp_data = {
51 std::map<int, std::string> snapshot_2 = table.retrieve_all();
53# if __cplusplus >= 201703L
55 auto result = table.find(100);
57 std::cout <<
"Found key 100: " << *result << std::endl;
59 std::cout <<
"Key 100 not found\n";
61 auto result = table.find_compat(100);
63 std::cout <<
"Found key 100: " << result.second << std::endl;
65 std::cout <<
"Key 100 not found\n";
69 bool erased = table.erase(200);
70 std::cout <<
"Erased key 200: " << erased << std::endl;
73 std::cout <<
"All key-value pairs:\n";
74 std::vector<std::pair<int, std::string>> all;
76 for (
size_t i = 0; i < all.size(); ++i)
77 std::cout << all[i].first <<
": " << all[i].second << std::endl;
81 std::cout <<
"After clear, size = " << table.count() << 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.
int main()
Basic example using Config to initialize a table.