7template <
typename MapType>
9 std::cout << header << std::endl;
10 for (
const auto& pair : map) {
11 if (!pair.second.empty()) {
12 for (
const auto& item : pair.second) {
13 std::cout <<
"Key: " << pair.first <<
" -> Value: " << item << std::endl;
16 std::cout <<
"Key: " << pair.first <<
" has an empty set." << std::endl;
25 config.
db_path =
"example-map-set.db";
35 std::map<int, std::set<int>> map_with_set_pairs = {
41 std::cout <<
"Appending data to the database using reconcile..." << std::endl;
42 key_value_db.
reconcile(map_with_set_pairs);
45 auto retrieved_map_with_set_pairs = key_value_db.
retrieve_all<std::map, std::set>();
46 print_map_with_set(retrieved_map_with_set_pairs,
"Key-value pairs in database after reconcile:");
53 retrieved_map_with_set_pairs = key_value_db.
retrieve_all<std::map, std::set>();
54 print_map_with_set(retrieved_map_with_set_pairs,
"Key-value pairs in database after inserting new values:");
57 std::cerr <<
"SQLite error: " << e.what() << std::endl;
58 }
catch (
const std::exception &e) {
59 std::cerr <<
"Error: " << e.what() << std::endl;
Template 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.
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.
void reconcile(const ContainerT< KeyT, ValueT > &container, const TransactionMode &mode)
Reconciles the content of the container with the database with a transaction.
Exception class for SQLite errors.
void print_map_with_set(const MapType &map, const std::string &header)