dodo
0.0.1
A C++ library to create containerized Linux services
|
Go to the documentation of this file.
23 #ifndef dodo_kvstore_hpp
24 #define dodo_kvstore_hpp
97 KVStore(
const std::filesystem::path &path );
119 bool deleteKey(
const std::string &key );
155 bool exists(
const std::string &key )
const;
163 void filterKeys( std::list<std::string>& keys,
const std::string &filter )
const;
178 bool getValue(
const std::string &key, std::string &value )
const;
186 bool getValue(
const std::string &key,
double &value )
const;
194 bool getValue(
const std::string &key, int64_t &value )
const;
210 bool insertKey(
const std::string &key,
const std::string &value );
218 bool insertKey(
const std::string &key,
const double &value );
226 bool insertKey(
const std::string &key,
const int64_t &value );
253 bool setKey(
const std::string &key,
const std::string &value );
261 bool setKey(
const std::string &key,
const double &value );
269 bool setKey(
const std::string &key,
const int64_t &value );
A persistent, multi-threaded key-value store backed by sqlite3 database (file).
bool getValue(const std::string &key, std::string &value) const
If the key exists, returns true and sets the value parameter.
sqlite::Query * stmt_metadata_
Get metadata statement handle.
sqlite::Query * stmt_getvalue_
Get-value-for-key statement handle.
void rollbackTransaction()
Rollback a transaction.
MetaData getMetaData(const std::string &key) const
Get MetaData for the key.
Queries can take bind values and return select lists.
An array of Octets with size elements.
bool exists(const std::string &key) const
Check if the key exists.
std::filesystem::path path_
The filesystem path to the kvstore.
void startTransaction()
Start a transaction.
void checkpoint()
Sync all to disk - issue a SQLite full checkpoint.
sqlite::DML * stmt_insert_
Insert key pair statement handle.
sqlite::Query * stmt_key_value_filter_
Key + value filter statement handle.
bool setKey(const std::string &key, const std::string &value)
Set the string value of an existing key.
bool insertKey(const std::string &key, const std::string &value)
Insert a (key, string) pair.
DataType
The data type of a select-list value.
void prepareSQL()
Prepare all SQL statements.
sqlite::Database * db_
The database handle.
KVStore(const std::filesystem::path &path)
Create the KVStore object against the path.
void filterKeys(std::list< std::string > &keys, const std::string &filter) const
Return a list of keys that match the filter.
void commitTransaction()
Commit a transaction.
std::string ensureWithDefault(const std::string &key, const std::string &def)
If the key does not exist, create it with the default and return the default.
sqlite::Query * stmt_exists_
check key existence statement handle.
void optimize()
Optimzime, preferably called after workload and implicitly called by the destructor.
Persistent storage structures.
Data Modification Language statements can take bind values.
bool deleteKey(const std::string &key)
Delete the key or return false if the key does not exist.
sqlite::Query * stmt_key_filter_
Key filter statement handle.
~KVStore()
Destructor, cleanup sync and close the SQLLite database.
void createSchema()
Create the SQLite schema.
sqlite::DML * stmt_update_
Update key pair statement handle.
A STL friendly wrapper around the great sqlite3.
void vacuum()
Vaccum - clean and defragment, which may increase efficiency after heavy deletion and/or modification...
sqlite::DML * stmt_delete_
Delete key pair statement handle.