13 config1.
db_path =
"example_multi_type.db";
20 config2.
db_path =
"example_multi_type.db";
27 config3.
db_path =
"example_multi_type.db";
34 config4.
db_path =
"example_multi_type.db";
46 std::set<int> int_keys = {1, 2, 3, 4};
50 kv_db.
insert(
"apple", 1.1);
51 kv_db.
insert(
"banana", 2.2);
52 kv_db.
insert(
"orange", 3.3);
55 kv_db2.
insert(1.5f,
"one point five");
56 kv_db2.
insert(2.7f,
"two point seven");
59 kmv_db.
insert(1,
"value1");
60 kmv_db.
insert(1,
"value2");
61 kmv_db.
insert(2,
"valueA");
62 kmv_db.
insert(2,
"valueB");
65 std::set<int> retrieved_int_keys = key_db.
retrieve_all<std::set>();
66 std::cout <<
"Keys in KeyDB: ";
67 for (
const auto& key : retrieved_int_keys) {
68 std::cout << key <<
" ";
70 std::cout << std::endl;
73 std::map<std::string, double> string_to_double = kv_db.
retrieve_all<std::map>();
74 std::cout <<
"String-to-Double KeyValueDB contents:" << std::endl;
75 for (
const auto& pair : string_to_double) {
76 std::cout <<
"Key: " << pair.first <<
", Value: " << pair.second << std::endl;
80 std::map<float, std::string> float_to_string = kv_db2.
retrieve_all<std::map>();
81 std::cout <<
"Float-to-String KeyValueDB contents:" << std::endl;
82 for (
const auto& pair : float_to_string) {
83 std::cout <<
"Key: " << pair.first <<
", Value: " << pair.second << std::endl;
87 std::multimap<int, std::string> int_to_multi_strings = kmv_db.
retrieve_all<std::multimap>();
88 std::cout <<
"Int-to-MultiStrings KeyMultiValueDB contents:" << std::endl;
89 for (
const auto& pair : int_to_multi_strings) {
90 std::cout <<
"Key: " << pair.first <<
", Value: " << pair.second << std::endl;
94 std::cerr <<
"SQLite error: " << e.what() << std::endl;
95 }
catch (
const std::exception& e) {
96 std::cerr <<
"Error: " << e.what() << std::endl;
Declaration of the KeyDB class for managing keys in a SQLite database.
Template class for managing key-value pairs in a SQLite database.
Declaration of the KeyValueDB class for managing key-value pairs in a SQLite database.
void connect()
Connects to the database using the current configuration. Initializes a connection to the database by...
Configuration class for SQLite database settings.
std::string db_path
Path to the SQLite database file.
std::string table_name
Name of the database table.
Template class for managing keys in a SQLite database.
ContainerT< KeyT > retrieve_all()
Retrieves all keys from the database.
void append(const ContainerT< KeyT > &container)
Appends the content of the container to the database.
void clear()
Clears all keys from the database.
Template class for managing key-value pairs in a SQLite database, where each key can map to multiple ...
ContainerT< KeyT, ValueT > retrieve_all(const TransactionMode &mode)
Retrieves all key-value pairs from the database with a transaction.
void insert(const KeyT &key, const ValueT &value, const TransactionMode &mode)
Inserts a key-value pair into the database with a transaction.
void clear(const TransactionMode &mode)
Clears all key-value pairs from the database with a transaction.
Template class for managing key-value pairs in a SQLite database.
void clear()
Clears all key-value pairs from the database.
void insert(const KeyT &key, const ValueT &value)
Inserts a key-value pair into the database.
ContainerT< KeyT, ValueT > retrieve_all()
Retrieves all key-value pairs.
Exception class for SQLite errors.