11 config.
db_path =
"example-set.db";
21 std::set<int> keys = {1, 2, 3, 4, 5};
27 std::set<int> retrieved_keys_set = key_db.
retrieve_all<std::set>();
28 std::cout <<
"Keys in database after append: ";
29 for (
const auto& key : retrieved_keys_set) {
30 std::cout << key <<
" ";
32 std::cout << std::endl;
35 std::cout <<
"Number of keys in the database: " << key_db.
count() << std::endl;
38 std::cout <<
"Is the database empty? " << (key_db.
empty() ?
"Yes" :
"No") << std::endl;
44 std::list<int> retrieved_keys_list = key_db.
retrieve_all<std::list>();
45 std::cout <<
"Keys in database after insert: ";
46 for (
const auto& key : retrieved_keys_list) {
47 std::cout << key <<
" ";
49 std::cout << std::endl;
53 std::cout <<
"Key 6 found in the database." << std::endl;
55 std::cout <<
"Key 6 not found in the database." << std::endl;
59 if (key_db.
find(10)) {
60 std::cout <<
"Key 10 found in the database." << std::endl;
62 std::cout <<
"Key 10 not found in the database." << std::endl;
69 std::vector<int> retrieved_keys_vector = key_db.
retrieve_all<std::vector>();
70 std::cout <<
"Keys in database after removing key 3: ";
71 for (
const auto& key : retrieved_keys_vector) {
72 std::cout << key <<
" ";
74 std::cout << std::endl;
77 std::set<int> new_keys = {10, 20, 30};
79 std::vector<int> keys_after_assignment = key_db.
retrieve_all<std::vector>();
80 std::cout <<
"Keys in database after using operator= with new set: ";
81 for (
const auto& key : keys_after_assignment) {
82 std::cout << key <<
" ";
84 std::cout << std::endl;
87 std::list<int> keys_loaded_with_operator = key_db.template operator()<std::list>();
88 std::cout <<
"Keys loaded using operator(): ";
89 for (
const auto& key : keys_loaded_with_operator) {
90 std::cout << key <<
" ";
92 std::cout << std::endl;
95 std::cout <<
"Number of keys in the database: " << key_db.
count() << std::endl;
98 std::cout <<
"Is the database empty? " << (key_db.
empty() ?
"Yes" :
"No") << std::endl;
101 std::cerr <<
"SQLite error: " << e.what() << std::endl;
102 }
catch (
const std::exception &e) {
103 std::cerr <<
"Error: " << e.what() << std::endl;
Declaration of the KeyDB class for managing keys 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 keys in a SQLite database.
std::size_t count() const
Returns the number of keys in the database.
bool empty() const
Checks if the database is empty (no keys present).
bool find(const KeyT &key)
Finds if a key exists in the 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 insert(const KeyT &key)
Inserts a key into the database.
void clear()
Clears all keys from the database.
void remove(const KeyT &key)
Removes a key from the database.
Exception class for SQLite errors.