diff options
Diffstat (limited to 'common/storage.h')
-rw-r--r-- | common/storage.h | 40 |
1 files changed, 34 insertions, 6 deletions
diff --git a/common/storage.h b/common/storage.h index 8904148..ac6509d 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,23 @@ 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 | // of QByteArray for keys | ||
89 | 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)>()); | ||
90 | |||
83 | /** | 91 | /** |
84 | * Remove a key | 92 | * Remove a key |
85 | */ | 93 | */ |
86 | void remove(const QByteArray &key, const std::function<void(const DataStore::Error &error)> &errorHandler = std::function<void(const DataStore::Error &error)>()); | 94 | void remove(const QByteArray &key, const std::function<void(const DataStore::Error &error)> &errorHandler = std::function<void(const DataStore::Error &error)>()); |
95 | |||
96 | void remove(const size_t key, const std::function<void(const DataStore::Error &error)> &errorHandler = std::function<void(const DataStore::Error &error)>()); | ||
97 | |||
87 | /** | 98 | /** |
88 | * Remove a key-value pair | 99 | * Remove a key-value pair |
89 | */ | 100 | */ |
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)>()); | 101 | 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 | 102 | ||
103 | 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)>()); | ||
104 | |||
92 | /** | 105 | /** |
93 | * Read values with a given key. | 106 | * Read values with a given key. |
94 | * | 107 | * |
@@ -101,6 +114,9 @@ public: | |||
101 | int scan(const QByteArray &key, const std::function<bool(const QByteArray &key, const QByteArray &value)> &resultHandler, | 114 | 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; | 115 | const std::function<void(const DataStore::Error &error)> &errorHandler = std::function<void(const DataStore::Error &error)>(), bool findSubstringKeys = false, bool skipInternalKeys = true) const; |
103 | 116 | ||
117 | int scan(const size_t key, const std::function<bool(size_t key, const QByteArray &value)> &resultHandler, | ||
118 | const std::function<void(const DataStore::Error &error)> &errorHandler = std::function<void(const DataStore::Error &error)>(), bool skipInternalKeys = true) const; | ||
119 | |||
104 | /** | 120 | /** |
105 | * Finds the last value in a series matched by prefix. | 121 | * Finds the last value in a series matched by prefix. |
106 | * | 122 | * |
@@ -110,6 +126,9 @@ public: | |||
110 | void findLatest(const QByteArray &uid, const std::function<void(const QByteArray &key, const QByteArray &value)> &resultHandler, | 126 | void findLatest(const QByteArray &uid, const std::function<void(const QByteArray &key, const QByteArray &value)> &resultHandler, |
111 | const std::function<void(const DataStore::Error &error)> &errorHandler = std::function<void(const DataStore::Error &error)>()) const; | 127 | const std::function<void(const DataStore::Error &error)> &errorHandler = std::function<void(const DataStore::Error &error)>()) const; |
112 | 128 | ||
129 | void findLatest(size_t key, const std::function<void(size_t key, const QByteArray &value)> &resultHandler, | ||
130 | const std::function<void(const DataStore::Error &error)> &errorHandler = std::function<void(const DataStore::Error &error)>()) const; | ||
131 | |||
113 | /** | 132 | /** |
114 | * Finds all the keys and values whose keys are in a given range | 133 | * Finds all the keys and values whose keys are in a given range |
115 | * (inclusive). | 134 | * (inclusive). |
@@ -119,6 +138,10 @@ public: | |||
119 | const std::function<void(const DataStore::Error &error)> &errorHandler = | 138 | const std::function<void(const DataStore::Error &error)> &errorHandler = |
120 | std::function<void(const DataStore::Error &error)>()) const; | 139 | std::function<void(const DataStore::Error &error)>()) const; |
121 | 140 | ||
141 | int findAllInRange(const size_t lowerBound, const size_t upperBound, | ||
142 | const std::function<void(size_t key, const QByteArray &value)> &resultHandler, | ||
143 | const std::function<void(const DataStore::Error &error)> &errorHandler = {}) const; | ||
144 | |||
122 | /** | 145 | /** |
123 | * Returns true if the database contains the substring key. | 146 | * Returns true if the database contains the substring key. |
124 | */ | 147 | */ |
@@ -163,8 +186,9 @@ public: | |||
163 | 186 | ||
164 | QList<QByteArray> getDatabaseNames() const; | 187 | QList<QByteArray> getDatabaseNames() const; |
165 | 188 | ||
166 | NamedDatabase openDatabase(const QByteArray &name = {"default"}, | 189 | NamedDatabase openDatabase(const QByteArray &name = { "default" }, |
167 | const std::function<void(const DataStore::Error &error)> &errorHandler = {}, bool allowDuplicates = false) const; | 190 | const std::function<void(const DataStore::Error &error)> &errorHandler = {}, |
191 | int flags = 0) const; | ||
168 | 192 | ||
169 | Transaction(Transaction &&other); | 193 | Transaction(Transaction &&other); |
170 | Transaction &operator=(Transaction &&other); | 194 | Transaction &operator=(Transaction &&other); |
@@ -224,13 +248,17 @@ public: | |||
224 | static qint64 cleanedUpRevision(const Transaction &); | 248 | static qint64 cleanedUpRevision(const Transaction &); |
225 | static void setCleanedUpRevision(Transaction &, qint64 revision); | 249 | static void setCleanedUpRevision(Transaction &, qint64 revision); |
226 | 250 | ||
227 | static QByteArray getUidFromRevision(const Transaction &, qint64 revision); | 251 | static QByteArray getUidFromRevision(const Transaction &, size_t revision); |
228 | static QByteArray getTypeFromRevision(const Transaction &, qint64 revision); | 252 | static size_t getLatestRevisionFromUid(Transaction &, const QByteArray &uid); |
229 | static void recordRevision(Transaction &, qint64 revision, const QByteArray &uid, const QByteArray &type); | 253 | static QList<size_t> getRevisionsUntilFromUid(DataStore::Transaction &, const QByteArray &uid, size_t lastRevision); |
230 | static void removeRevision(Transaction &, qint64 revision); | 254 | static QList<size_t> getRevisionsFromUid(DataStore::Transaction &, const QByteArray &uid); |
255 | static QByteArray getTypeFromRevision(const Transaction &, size_t revision); | ||
256 | static void recordRevision(Transaction &, size_t revision, const QByteArray &uid, const QByteArray &type); | ||
257 | static void removeRevision(Transaction &, size_t revision); | ||
231 | static void recordUid(DataStore::Transaction &transaction, const QByteArray &uid, const QByteArray &type); | 258 | 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); | 259 | 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)> &); | 260 | static void getUids(const QByteArray &type, const Transaction &, const std::function<void(const QByteArray &uid)> &); |
261 | static bool hasUid(const QByteArray &type, const Transaction &, const QByteArray &uid); | ||
234 | 262 | ||
235 | bool exists() const; | 263 | bool exists() const; |
236 | static bool exists(const QString &storageRoot, const QString &name); | 264 | static bool exists(const QString &storageRoot, const QString &name); |