![]() |
SQLite Containers
|
Template class for managing keys in a SQLite database. More...
#include <KeyDB.hpp>
Public Member Functions | |
| KeyDB () | |
| Default constructor. | |
| KeyDB (const Config &config) | |
| Constructor with configuration. | |
| ~KeyDB () override final=default | |
| Destructor. | |
| template<template< class... > class ContainerT> | |
| KeyDB & | operator= (const ContainerT< KeyT > &container) |
| Assigns a container (e.g., std::set, std::unordered_set, std::vector, or std::list) to the database. | |
| template<template< class... > class ContainerT = std::set> | |
| ContainerT< KeyT > | operator() () |
| Loads all keys from the database into a container (e.g., std::set, std::unordered_set, std::vector, or std::list). | |
| template<template< class... > class ContainerT> | |
| void | load (ContainerT< KeyT > &container) |
| Loads data from the database into the container. | |
| template<template< class... > class ContainerT> | |
| void | load (ContainerT< KeyT > &container, const TransactionMode &mode) |
| Loads data from the database into the container with a transaction. | |
| template<template< class... > class ContainerT> | |
| ContainerT< KeyT > | retrieve_all () |
| Retrieves all keys from the database. | |
| template<template< class... > class ContainerT> | |
| ContainerT< KeyT > | retrieve_all (const TransactionMode &mode) |
| Retrieves all keys from the database with a transaction. | |
| template<template< class... > class ContainerT> | |
| void | append (const ContainerT< KeyT > &container) |
| Appends the content of the container to the database. | |
| template<template< class... > class ContainerT> | |
| void | append (const ContainerT< KeyT > &container, const TransactionMode &mode) |
| Appends the content of the container to the database with a transaction. | |
| template<template< class... > class ContainerT> | |
| void | reconcile (const ContainerT< KeyT > &container) |
| Reconciles the database with the container. | |
| template<template< class... > class ContainerT> | |
| void | reconcile (const ContainerT< KeyT > &container, const TransactionMode &mode) |
| Reconciles the database with the container using a transaction. | |
| void | insert (const KeyT &key) |
| Inserts a key into the database. | |
| bool | find (const KeyT &key) |
| Finds if a key exists in the 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). | |
| void | remove (const KeyT &key) |
| Removes a key from the database. | |
| void | clear () |
| Clears all keys from the database. | |
Public Member Functions inherited from sqlite_containers::BaseDB | |
| BaseDB ()=default | |
| Default constructor. | |
| virtual | ~BaseDB () |
| Destructor. Disconnects from the database if connected. | |
| void | set_config (const Config &config) |
| Sets the configuration for the database. | |
| Config | get_config () const |
| Gets the current configuration of the database. | |
| void | connect () |
| Connects to the database using the current configuration. Initializes a connection to the database by creating necessary directories, opening the database, creating tables, and setting up database parameters. | |
| void | connect (const Config &config) |
| Connects to the database with the given configuration. | |
| void | disconnect () |
| Disconnects from the database. | |
| void | begin (const TransactionMode &mode=TransactionMode::DEFERRED) |
| Begins a database transaction. | |
| void | commit () |
| Commits the current transaction. | |
| void | rollback () |
| Rolls back the current transaction. | |
| template<typename Func> | |
| void | execute_in_transaction (Func operation, const TransactionMode &mode) |
| Executes an operation inside a transaction. | |
| virtual void | process () |
| Processes asynchronous database requests (can be overridden). | |
Private Member Functions | |
| void | db_create_table (const Config &config) override final |
| Creates the table in the database. | |
| template<template< class... > class ContainerT> | |
| void | db_load (ContainerT< KeyT > &container) |
| Loads data from the database into the container. | |
| bool | db_find (const KeyT &key) |
| Finds if a key exists in the database. | |
| std::size_t | db_count () const |
| Returns the total number of keys stored in the database. | |
| template<template< class... > class ContainerT> | |
| void | db_reconcile (const ContainerT< KeyT > &container) |
| Reconciles the content of the database with the container. Synchronizes the main table with the content of the container by using a temporary table. Clears old data, inserts new data, and updates existing records in the main table. | |
| template<template< class... > class ContainerT> | |
| void | db_append (const ContainerT< KeyT > &container) |
| Appends the content of the container to the database. | |
| void | db_insert (const KeyT &key) |
| Inserts a key into the database. | |
| void | db_remove (const KeyT &key) |
| Removes a key from the database. | |
| void | db_clear () |
| Clears all keys from the database. | |
Private Attributes | |
| SqliteStmt | m_stmt_load |
| Statement for loading data from the database. | |
| SqliteStmt | m_stmt_replace |
| Statement for replacing key-value pairs in the database. | |
| SqliteStmt | m_stmt_find |
| Statement for finding a key. | |
| SqliteStmt | m_stmt_count |
| Statement for counting the number of keys in the database. | |
| SqliteStmt | m_stmt_remove |
| Statement for removing a key. | |
| SqliteStmt | m_stmt_clear |
| Statement for clearing the table. | |
| SqliteStmt | m_stmt_insert_temp |
| Statement for inserting data into the temporary table. | |
| SqliteStmt | m_stmt_purge_main |
| Statement for purging stale data from the main table. | |
| SqliteStmt | m_stmt_merge_temp |
| Statement for merging data from the temporary table into the main table. | |
| SqliteStmt | m_stmt_clear_temp |
| Statement for clearing the temporary table. | |
Additional Inherited Members | |
Protected Member Functions inherited from sqlite_containers::BaseDB | |
| void | db_begin (const TransactionMode &mode=TransactionMode::DEFERRED) |
| Begins a transaction with the given mode. | |
| void | db_commit () |
| Commits the current transaction. | |
| void | db_rollback () |
| Rolls back the current transaction. | |
| void | db_handle_exception (std::exception_ptr ex, const std::vector< SqliteStmt * > &stmts, const std::string &message="Unknown error occurred.") const |
| Handles an exception by resetting and clearing bindings of prepared SQL statements. | |
| virtual void | on_db_open () |
| Called after the database is opened. Can be overridden in derived classes. | |
| virtual void | on_db_close () |
| Called before the database is closed. Can be overridden in derived classes. | |
Protected Attributes inherited from sqlite_containers::BaseDB | |
| sqlite3 * | m_sqlite_db = nullptr |
| std::mutex | m_sqlite_mutex |
Template class for managing keys in a SQLite database.
| KeyT | Type of the keys. |
This class supports various container types, including std::set, std::unordered_set, std::vector, and std::list. The class allows insertion, retrieval, and removal of keys from a SQLite database while maintaining transactional integrity.
|
inline |
|
inline |
|
finaloverridedefault |
Destructor.
|
inline |
Appends the content of the container to the database.
| ContainerT | Template for the container type (vector, deque, list, set or unordered_set). |
| container | Container with content to be synchronized to the database. |
| sqlite_exception | if an SQLite error occurs. |
|
inline |
Appends the content of the container to the database with a transaction.
| ContainerT | Template for the container type (vector, deque, list, set or unordered_set). |
| container | Container with content to be synchronized to the database. |
| mode | Transaction mode. |
| sqlite_exception | if an SQLite error occurs. |
|
inline |
Clears all keys from the database.
| sqlite_exception | if an SQLite error occurs. |
|
inline |
Returns the number of keys in the database.
| sqlite_exception | if an SQLite error occurs. |
|
inlineprivate |
Appends the content of the container to the database.
| ContainerT | Template for the container type (vector, deque, list, set or unordered_set). |
| container | Container with content to be synchronized to the database. |
| sqlite_exception | if an SQLite error occurs. |
|
inlineprivate |
Clears all keys from the database.
| sqlite_exception | if an SQLite error occurs. |
|
inlineprivate |
Returns the total number of keys stored in the database.
| sqlite_exception | if an SQLite error occurs. |
|
inlinefinaloverrideprivatevirtual |
Creates the table in the database.
| config | Configuration settings. |
Implements sqlite_containers::BaseDB.
|
inlineprivate |
Finds if a key exists in the database.
| key | The key to search for. |
| sqlite_exception | if an SQLite error occurs. |
|
inlineprivate |
Inserts a key into the database.
| key | The key to be inserted. |
| sqlite_exception | if an SQLite error occurs. |
|
inlineprivate |
Loads data from the database into the container.
| ContainerT | Template for the container type (vector, deque, list, set or unordered_set). |
| set | Container to be synchronized with database content. |
| sqlite_exception | if an SQLite error occurs. |
|
inlineprivate |
Reconciles the content of the database with the container. Synchronizes the main table with the content of the container by using a temporary table. Clears old data, inserts new data, and updates existing records in the main table.
| ContainerT | Template for the container type (e.g., std::set, std::unordered_set, std::vector, or std::list). |
| container | Container with keys to be reconciled with the database. |
| sqlite_exception | if an SQLite error occurs. |
|
inlineprivate |
Removes a key from the database.
| key | The key to be removed. |
| sqlite_exception | if an SQLite error occurs. |
|
inline |
Checks if the database is empty (no keys present).
| sqlite_exception | if an SQLite error occurs. |
|
inline |
Finds if a key exists in the database.
| key | The key to search for. |
| sqlite_exception | if an SQLite error occurs. |
|
inline |
Inserts a key into the database.
| key | The key to be inserted. |
| sqlite_exception | if an SQLite error occurs. |
|
inline |
Loads data from the database into the container.
| ContainerT | Template for the container type (vector, deque, list, set or unordered_set). |
| container | Container to be synchronized with database content. |
| sqlite_exception | if an SQLite error occurs. |
|
inline |
Loads data from the database into the container with a transaction.
| ContainerT | Template for the container type (vector, deque, list, set or unordered_set). |
| container | Container to be synchronized with database content. |
| mode | Transaction mode. |
| sqlite_exception | if an SQLite error occurs. |
|
inline |
Loads all keys from the database into a container (e.g., std::set, std::unordered_set, std::vector, or std::list).
| ContainerT | The type of the container (e.g., std::set, std::unordered_set, std::vector, or std::list). |
| sqlite_exception | if an SQLite error occurs. |
|
inline |
Assigns a container (e.g., std::set, std::unordered_set, std::vector, or std::list) to the database.
| ContainerT | The type of the container (e.g., std::set, std::unordered_set). |
| container | The container with keys to be inserted into the database. |
| sqlite_exception | if an SQLite error occurs. |
|
inline |
Reconciles the database with the container.
| ContainerT | Container type (e.g., std::set, std::unordered_set, std::vector, or std::list). |
| container | Container to be reconciled with the database. |
| sqlite_exception | if an SQLite error occurs. |
|
inline |
Reconciles the database with the container using a transaction.
| ContainerT | Container type (e.g., std::set, std::unordered_set, std::vector, or std::list). |
| container | Container to be reconciled with the database. |
| mode | Transaction mode. |
| sqlite_exception | if an SQLite error occurs. |
|
inline |
Removes a key from the database.
| key | The key to be removed. |
| sqlite_exception | if an SQLite error occurs. |
|
inline |
Retrieves all keys from the database.
| ContainerT | Template for the container type (vector, deque, list, set or unordered_set). |
| sqlite_exception | if an SQLite error occurs. |
|
inline |
Retrieves all keys from the database with a transaction.
| ContainerT | Template for the container type (vector, deque, list, set or unordered_set). |
| mode | Transaction mode. |
| sqlite_exception | if an SQLite error occurs. |
|
private |
|
private |
|
mutableprivate |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |