MDBX Containers
Loading...
Searching...
No Matches
multi_table_demo.cpp
Go to the documentation of this file.
1
5
8#include <iostream>
9#include <limits>
10
11int main() {
12 mdbxc::Config config;
13 config.pathname = "multi_table_db";
14 config.max_dbs = 2;
15
16 auto conn = mdbxc::Connection::create(config);
17
18 mdbxc::KeyValueTable<int, std::string> int_to_str_table(conn, "kv_table1");
19 mdbxc::KeyValueTable<std::string, std::string> str_to_str_table(conn, "kv_table2");
20
21 int_to_str_table.clear();
22 str_to_str_table.clear();
23
24 int_to_str_table.insert_or_assign(100, "hundred");
25 str_to_str_table.insert_or_assign("a", "b");
26
27# if __cplusplus >= 201703L
28 auto val1 = int_to_str_table.find(100);
29 auto val2 = str_to_str_table.find("a");
30 if (val1)
31 std::cout << "kv_table1[100]: " << *val1 << std::endl;
32 else
33 std::cout << "kv_table1[100]: not found" << std::endl;
34
35 if (val2)
36 std::cout << "kv_table2[\"a\"]: " << *val2 << std::endl;
37 else
38 std::cout << "kv_table2[\"a\"]: not found" << std::endl;
39# else
40 auto val1 = int_to_str_table.find_compat(100);
41 auto val2 = str_to_str_table.find_compat("a");
42 if (val1.first)
43 std::cout << "kv_table1[100]: " << val1.second << std::endl;
44 else
45 std::cout << "kv_table1[100]: not found" << std::endl;
46
47 if (val2.first)
48 std::cout << "kv_table2[\"a\"]: " << val2.second << std::endl;
49 else
50 std::cout << "kv_table2[\"a\"]: not found" << std::endl;
51# endif
52
53 std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
54 std::cin.get();
55 return 0;
56}
Declaration of the KeyValueTable class for managing key-value pairs in an MDBX database.
int main()
Entry point demonstrating AnyValueTable.
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
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.