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