From ef3b24358e508c5220d8b2548ec7207936794c66 Mon Sep 17 00:00:00 2001 From: Aaron Seigo Date: Thu, 4 Dec 2014 15:49:02 +0100 Subject: hide the implementation detail of which key/value store we use also makes transactions "implicit" where necessary. this will make trying out other k/v stores a bit easier now as well. --- store/database.h | 35 +++++++++++------------------------ 1 file changed, 11 insertions(+), 24 deletions(-) (limited to 'store/database.h') diff --git a/store/database.h b/store/database.h index ab398a4..2bf0556 100644 --- a/store/database.h +++ b/store/database.h @@ -1,38 +1,25 @@ #pragma once -#include #include #include class Database { public: + enum TransactionType { ReadOnly, ReadWrite }; + Database(const QString &path); ~Database(); - MDB_txn *startTransaction(); - void endTransaction(MDB_txn *transaction); - void write(const std::string &sKey, const std::string &sValue, MDB_txn *transaction); + bool isInTransaction() const; + bool startTransaction(TransactionType type = ReadWrite); + bool commitTransaction(); + void abortTransaction(); + bool write(const std::string &sKey, const std::string &sValue); //Perhaps prefer iterators (assuming we need to be able to match multiple values - void read(const std::string &sKey, const std::function &); - -private: - MDB_env *env; - MDB_dbi dbi; -}; - -/* - * This opens the db for a single read transaction. - * - * The lifetime of all read values is tied to this transaction. - */ -class ReadTransaction { -public: - ReadTransaction(const QString &path); - ~ReadTransaction(); - + void read(const std::string &sKey, const std::function &); void read(const std::string &sKey, const std::function &); private: - MDB_env *env; - MDB_dbi dbi; - MDB_txn *txn; + class Private; + Private * const d; }; + -- cgit v1.2.3