diff options
Diffstat (limited to 'store/database.h')
-rw-r--r-- | store/database.h | 35 |
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 | ||
7 | class Database { | 6 | class Database { |
8 | public: | 7 | public: |
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 | |||
17 | private: | ||
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 | */ | ||
27 | class ReadTransaction { | ||
28 | public: | ||
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 | ||
34 | private: | 21 | private: |
35 | MDB_env *env; | 22 | class Private; |
36 | MDB_dbi dbi; | 23 | Private * const d; |
37 | MDB_txn *txn; | ||
38 | }; | 24 | }; |
25 | |||