Newer
Older
#ifndef __VEREIGN_KVSTORE_SQLITE_STORAGE_HH
#define __VEREIGN_KVSTORE_SQLITE_STORAGE_HH
#include <vereign/kvstore/storage.hh>
#include <vereign/sqlite/connection.hh>
namespace vereign::kvstore {
/**
* Sqlite implementation of the kvstore::Storage interface.
*/
class SqliteStorage : public Storage {
public:
/**
* Creates SqliteStorage instance.
*
* @param db_path Full path to the sqlite database file.
*/
~SqliteStorage() override;
SqliteStorage(const SqliteStorage&) = delete;
auto operator=(const SqliteStorage&) -> SqliteStorage& = delete;
/**
* Locks the storage.
*
* The lock must be recursive, meaning that may be called multiple times.
* Storage::Unlock must be called the same number of times the Storage::Lock was called.
*
* Use kvstore::Lock for lock guard and lock with retrials.
*
* @throws LockError when the lock is held by another process.
*/
/**
* Locks the storage.
*
* The lock must be recursive, meaning that may be called multiple times.
* Storage::Unlock must be called the same number of times the Storage::Lock was called.
*
* Use kvstore::Lock for lock guard and lock with retrials.
*/
/**
* Deletes all the values in the storage.
*
* @throws sqlite::Error on failure.
*/
/**
* Store bytes value into the storage.
*
* @param key The key under which the value will be stored.
* @param value The bytes that will be stored.
*
* @throws sqlite::Error on failure.
*/
void PutBytes(const std::string& key, bytes::View value) override;
/**
* Retrieve bytes value from the storage.
*
* @param key The key of the value that will be retrieved.
* @param value Buffer where the value will be returned.
*
* @throws ValueNotFoundError when the key does not exist.
* @throws sqlite::Error on failure.
*/
void GetBytes(const std::string& key, bytes::Buffer& value) override;
/**
* Store int64_t value into the storage.
*
* @param key The key under which the value will be stored.
* @param value The value that will be stored.
*
* @throws sqlite::Error on failure.
*/
void PutInt64(const std::string& key, int64_t value) override;
/**
* Retrieve int64_t value from the storage.
*
* @param key The key of the value that will be retrieved.
* @param value Buffer where the value will be returned.
*
* @throws ValueNotFoundError when the key does not exist.
* @throws sqlite::Error on failure.
*/
auto GetInt64(const std::string& key) -> int64_t override;
private:
sqlite::Connection db_;
};
} // namespace vereign::kvstore
#endif // __VEREIGN_KVSTORE_SQLITE_STORAGE_HH