dodo
0.0.1
A C++ library to create containerized Linux services
|
Go to the documentation of this file.
75 pragma.
prepare(
"PRAGMA journal_mode=WAL;" );
80 ddl.
prepare(
"CREATE TABLE IF NOT EXISTS kvstore ( "
81 "key TEXT NOT NULL PRIMARY KEY, "
83 "modified NUMBER NOT NULL DEFAULT ((julianday('now') - 2440587.5) * 86400.0), "
84 "updates INTEGER NOT NULL DEFAULT 0"
94 return (affected == 1);
162 }
else result =
false;
173 }
else result =
false;
184 }
else result =
false;
195 }
else result =
false;
237 ddl.
prepare(
"PRAGMA optimize;" );
243 ddl.
prepare(
"PRAGMA case_sensitive_like=ON;" );
250 stmt_update_->
prepare(
"UPDATE kvstore SET value = ?, modified = ((julianday('now') - 2440587.5) * 86400.0), updates = updates + 1 WHERE key = ?" );
294 ddl.
prepare(
"BEGIN TRANSACTION" );
void rollback()
Rollback a transaction.
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.
void commit()
Commit 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::string getText(int col) const
Get string value from select list.
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.
bool step()
Step the result list, end of list returns false.
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.
DataType getDataType(int col) const
Get the dataype of a select list column.
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.
void bind(int position, double value)
Bind a double value to the bind at position.
void prepare(const std::string &sql)
Prepare a SQL statement.
bool deleteKey(const std::string &key)
Delete the key or return false if the key does not exist.
int execute()
Execute and return the number of rows affected.
sqlite::Query * stmt_key_filter_
Key filter statement handle.
int64_t getInt64(int col) const
Get int64_t value from select list.
~KVStore()
Destructor, cleanup sync and close the SQLLite database.
void createSchema()
Create the SQLite schema.
void reset(bool clear=true)
Reset a SQL statement for re-execute or even re-prepare.
sqlite::DML * stmt_update_
Update key pair statement handle.
A STL friendly wrapper around the great sqlite3.
Data Definition Language, SQL that takes no parameters, returns no data such as CREATE TABLE.
double getDouble(int col) const
Get double value from select list.
void vacuum()
Vaccum - clean and defragment, which may increase efficiency after heavy deletion and/or modification...
void execute()
execute, throws Oops on error.
sqlite::DML * stmt_delete_
Delete key pair statement handle.
void getBytes(int col, common::Bytes &bytes) const
Get Bytes value from select list.
void checkPointFull()
Issue a full checpoint.
int getInt(int col) const
Get int value from select list.