diff options
author | Minijackson <minijackson@riseup.net> | 2018-08-21 12:03:40 +0200 |
---|---|---|
committer | Minijackson <minijackson@riseup.net> | 2018-08-21 14:04:56 +0200 |
commit | 23e13c91e44e9d1fcbe2215f16d10117de4d0e84 (patch) | |
tree | 6e341ca4bcb94499a9b9631b7b3499a691d30b79 /common/storage.h | |
parent | 40fbc56ba745322ed75ac12c5551ce6b9bcb1cc4 (diff) | |
download | sink-23e13c91e44e9d1fcbe2215f16d10117de4d0e84.tar.gz sink-23e13c91e44e9d1fcbe2215f16d10117de4d0e84.zip |
Separate UIDs and revisions
Diffstat (limited to 'common/storage.h')
-rw-r--r-- | common/storage.h | 36 |
1 files changed, 30 insertions, 6 deletions
diff --git a/common/storage.h b/common/storage.h index 8904148..53fcf41 100644 --- a/common/storage.h +++ b/common/storage.h | |||
@@ -32,6 +32,11 @@ | |||
32 | namespace Sink { | 32 | namespace Sink { |
33 | namespace Storage { | 33 | namespace Storage { |
34 | 34 | ||
35 | extern int AllowDuplicates; | ||
36 | extern int IntegerKeys; | ||
37 | // Only useful with AllowDuplicates | ||
38 | extern int IntegerValues; | ||
39 | |||
35 | struct SINK_EXPORT DbLayout { | 40 | struct SINK_EXPORT DbLayout { |
36 | typedef QMap<QByteArray, int> Databases; | 41 | typedef QMap<QByteArray, int> Databases; |
37 | DbLayout(); | 42 | DbLayout(); |
@@ -80,15 +85,24 @@ public: | |||
80 | */ | 85 | */ |
81 | bool write(const QByteArray &key, const QByteArray &value, const std::function<void(const DataStore::Error &error)> &errorHandler = std::function<void(const DataStore::Error &error)>()); | 86 | bool write(const QByteArray &key, const QByteArray &value, const std::function<void(const DataStore::Error &error)> &errorHandler = std::function<void(const DataStore::Error &error)>()); |
82 | 87 | ||
88 | // TODO: change resultHandlers and errorHandlers to take size_t instead | ||
89 | // of QByteArray for keys | ||
90 | bool write(const size_t key, const QByteArray &value, const std::function<void(const DataStore::Error &error)> &errorHandler = std::function<void(const DataStore::Error &error)>()); | ||
91 | |||
83 | /** | 92 | /** |
84 | * Remove a key | 93 | * Remove a key |
85 | */ | 94 | */ |
86 | void remove(const QByteArray &key, const std::function<void(const DataStore::Error &error)> &errorHandler = std::function<void(const DataStore::Error &error)>()); | 95 | void remove(const QByteArray &key, const std::function<void(const DataStore::Error &error)> &errorHandler = std::function<void(const DataStore::Error &error)>()); |
96 | |||
97 | void remove(const size_t key, const std::function<void(const DataStore::Error &error)> &errorHandler = std::function<void(const DataStore::Error &error)>()); | ||
98 | |||
87 | /** | 99 | /** |
88 | * Remove a key-value pair | 100 | * Remove a key-value pair |
89 | */ | 101 | */ |
90 | void remove(const QByteArray &key, const QByteArray &value, const std::function<void(const DataStore::Error &error)> &errorHandler = std::function<void(const DataStore::Error &error)>()); | 102 | void remove(const QByteArray &key, const QByteArray &value, const std::function<void(const DataStore::Error &error)> &errorHandler = std::function<void(const DataStore::Error &error)>()); |
91 | 103 | ||
104 | void remove(const size_t key, const QByteArray &value, const std::function<void(const DataStore::Error &error)> &errorHandler = std::function<void(const DataStore::Error &error)>()); | ||
105 | |||
92 | /** | 106 | /** |
93 | * Read values with a given key. | 107 | * Read values with a given key. |
94 | * | 108 | * |
@@ -101,6 +115,9 @@ public: | |||
101 | int scan(const QByteArray &key, const std::function<bool(const QByteArray &key, const QByteArray &value)> &resultHandler, | 115 | int scan(const QByteArray &key, const std::function<bool(const QByteArray &key, const QByteArray &value)> &resultHandler, |
102 | const std::function<void(const DataStore::Error &error)> &errorHandler = std::function<void(const DataStore::Error &error)>(), bool findSubstringKeys = false, bool skipInternalKeys = true) const; | 116 | const std::function<void(const DataStore::Error &error)> &errorHandler = std::function<void(const DataStore::Error &error)>(), bool findSubstringKeys = false, bool skipInternalKeys = true) const; |
103 | 117 | ||
118 | int scan(const size_t key, const std::function<bool(size_t key, const QByteArray &value)> &resultHandler, | ||
119 | const std::function<void(const DataStore::Error &error)> &errorHandler = std::function<void(const DataStore::Error &error)>(), bool skipInternalKeys = true) const; | ||
120 | |||
104 | /** | 121 | /** |
105 | * Finds the last value in a series matched by prefix. | 122 | * Finds the last value in a series matched by prefix. |
106 | * | 123 | * |
@@ -119,6 +136,10 @@ public: | |||
119 | const std::function<void(const DataStore::Error &error)> &errorHandler = | 136 | const std::function<void(const DataStore::Error &error)> &errorHandler = |
120 | std::function<void(const DataStore::Error &error)>()) const; | 137 | std::function<void(const DataStore::Error &error)>()) const; |
121 | 138 | ||
139 | int findAllInRange(const size_t lowerBound, const size_t upperBound, | ||
140 | const std::function<void(const QByteArray &key, const QByteArray &value)> &resultHandler, | ||
141 | const std::function<void(const DataStore::Error &error)> &errorHandler = {}) const; | ||
142 | |||
122 | /** | 143 | /** |
123 | * Returns true if the database contains the substring key. | 144 | * Returns true if the database contains the substring key. |
124 | */ | 145 | */ |
@@ -163,8 +184,9 @@ public: | |||
163 | 184 | ||
164 | QList<QByteArray> getDatabaseNames() const; | 185 | QList<QByteArray> getDatabaseNames() const; |
165 | 186 | ||
166 | NamedDatabase openDatabase(const QByteArray &name = {"default"}, | 187 | NamedDatabase openDatabase(const QByteArray &name = { "default" }, |
167 | const std::function<void(const DataStore::Error &error)> &errorHandler = {}, bool allowDuplicates = false) const; | 188 | const std::function<void(const DataStore::Error &error)> &errorHandler = {}, |
189 | int flags = 0) const; | ||
168 | 190 | ||
169 | Transaction(Transaction &&other); | 191 | Transaction(Transaction &&other); |
170 | Transaction &operator=(Transaction &&other); | 192 | Transaction &operator=(Transaction &&other); |
@@ -224,10 +246,12 @@ public: | |||
224 | static qint64 cleanedUpRevision(const Transaction &); | 246 | static qint64 cleanedUpRevision(const Transaction &); |
225 | static void setCleanedUpRevision(Transaction &, qint64 revision); | 247 | static void setCleanedUpRevision(Transaction &, qint64 revision); |
226 | 248 | ||
227 | static QByteArray getUidFromRevision(const Transaction &, qint64 revision); | 249 | static QByteArray getUidFromRevision(const Transaction &, size_t revision); |
228 | static QByteArray getTypeFromRevision(const Transaction &, qint64 revision); | 250 | static size_t getLatestRevisionFromUid(Transaction &, const QByteArray &uid); |
229 | static void recordRevision(Transaction &, qint64 revision, const QByteArray &uid, const QByteArray &type); | 251 | static QList<size_t> getRevisionsUntilFromUid(DataStore::Transaction &, const QByteArray &uid, size_t lastRevision); |
230 | static void removeRevision(Transaction &, qint64 revision); | 252 | static QByteArray getTypeFromRevision(const Transaction &, size_t revision); |
253 | static void recordRevision(Transaction &, size_t revision, const QByteArray &uid, const QByteArray &type); | ||
254 | static void removeRevision(Transaction &, size_t revision); | ||
231 | static void recordUid(DataStore::Transaction &transaction, const QByteArray &uid, const QByteArray &type); | 255 | static void recordUid(DataStore::Transaction &transaction, const QByteArray &uid, const QByteArray &type); |
232 | static void removeUid(DataStore::Transaction &transaction, const QByteArray &uid, const QByteArray &type); | 256 | static void removeUid(DataStore::Transaction &transaction, const QByteArray &uid, const QByteArray &type); |
233 | static void getUids(const QByteArray &type, const Transaction &, const std::function<void(const QByteArray &uid)> &); | 257 | static void getUids(const QByteArray &type, const Transaction &, const std::function<void(const QByteArray &uid)> &); |