summaryrefslogtreecommitdiffstats
path: root/store/database.h
diff options
context:
space:
mode:
Diffstat (limited to 'store/database.h')
-rw-r--r--store/database.h35
1 files changed, 11 insertions, 24 deletions
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 @@
1#pragma once 1#pragma once
2 2
3#include <lmdb.h>
4#include <string> 3#include <string>
5#include <QString> 4#include <QString>
6 5
7class Database { 6class Database {
8public: 7public:
8 enum TransactionType { ReadOnly, ReadWrite };
9
9 Database(const QString &path); 10 Database(const QString &path);
10 ~Database(); 11 ~Database();
11 MDB_txn *startTransaction(); 12 bool isInTransaction() const;
12 void endTransaction(MDB_txn *transaction); 13 bool startTransaction(TransactionType type = ReadWrite);
13 void write(const std::string &sKey, const std::string &sValue, MDB_txn *transaction); 14 bool commitTransaction();
15 void abortTransaction();
16 bool write(const std::string &sKey, const std::string &sValue);
14 //Perhaps prefer iterators (assuming we need to be able to match multiple values 17 //Perhaps prefer iterators (assuming we need to be able to match multiple values
15 void read(const std::string &sKey, const std::function<void(const std::string)> &); 18 void read(const std::string &sKey, const std::function<void(const std::string &value)> &);
16
17private:
18 MDB_env *env;
19 MDB_dbi dbi;
20};
21
22/*
23 * This opens the db for a single read transaction.
24 *
25 * The lifetime of all read values is tied to this transaction.
26 */
27class ReadTransaction {
28public:
29 ReadTransaction(const QString &path);
30 ~ReadTransaction();
31
32 void read(const std::string &sKey, const std::function<void(void *ptr, int size)> &); 19 void read(const std::string &sKey, const std::function<void(void *ptr, int size)> &);
33 20
34private: 21private:
35 MDB_env *env; 22 class Private;
36 MDB_dbi dbi; 23 Private * const d;
37 MDB_txn *txn;
38}; 24};
25