8template <
typename MapType>
9void print_map(
const MapType& map,
const std::string& header) {
10 std::cout << header << std::endl;
11 for (
const auto& pair : map) {
12 std::cout <<
"Key: " << pair.first <<
", Value: ";
13 for (
char c : pair.second) {
16 std::cout << std::endl;
23 config.
db_path =
"example_vector.db";
30 map_db.
insert(1, {
'a',
'b',
'c'});
31 map_db.
insert(2, {
'd',
'e',
'f'});
32 map_db.
insert(3, {
'g',
'h',
'i'});
35 std::vector<char> value;
36 if (map_db.
find(2, value)) {
37 std::cout <<
"Found value for key 2: ";
38 for (
char c : value) {
41 std::cout << std::endl;
43 std::cout <<
"Key 2 not found." << std::endl;
47 std::map<int, std::vector<char>> my_map;
49 print_map(my_map,
"Contents of my_map after load:");
52 std::map<int, std::vector<char>> all_entries = map_db.
retrieve_all<std::map>();
53 print_map(all_entries,
"Contents of the database using retrieve_all:");
58 print_map(all_entries,
"Contents of the database after removing key 3:");
61 map_db.
insert(4, {
'j',
'k',
'l'});
63 print_map(all_entries,
"Contents of the database after inserting key 4:");
66 my_map[5] = {
'm',
'n',
'o'};
69 print_map(all_entries,
"Contents of the database after append:");
73 my_map[6] = {
'p',
'q',
'r'};
76 print_map(all_entries,
"Contents of the database after reconcile:");
80 my_map[7] = {
's',
't',
'u'};
83 print_map(all_entries,
"Contents of the database after using operator= to reconcile:");
88 if (all_entries.empty()) {
89 std::cout <<
"Database is empty after clear." << std::endl;
91 print_map(all_entries,
"Contents of the database after clear:");
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.
Template class for managing key-value pairs in a SQLite database.
void clear()
Clears all key-value pairs from the database.
void remove(const KeyT &key)
Removes a key-value pair from the database.
void reconcile(const ContainerT< KeyT, ValueT > &container)
Reconciles the database with the container.
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.
bool find(const KeyT &key, ValueT &value)
Finds a value by key.
void append(const ContainerT< KeyT, ValueT > &container)
Appends data to the database.
void load(ContainerT< KeyT, ValueT > &container)
Loads data from the database into the container.
void print_map(const MapType &map, const std::string &header)