summaryrefslogtreecommitdiffstats
path: root/common/index.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'common/index.cpp')
-rw-r--r--common/index.cpp14
1 files changed, 9 insertions, 5 deletions
diff --git a/common/index.cpp b/common/index.cpp
index f3d05f1..f09e265 100644
--- a/common/index.cpp
+++ b/common/index.cpp
@@ -18,22 +18,26 @@ Index::Index(const QByteArray &name, Sink::Storage::DataStore::Transaction &tran
18 18
19void Index::add(const QByteArray &key, const QByteArray &value) 19void Index::add(const QByteArray &key, const QByteArray &value)
20{ 20{
21 mDb.write(key, value); 21 mDb.write(key, value, [&] (const Sink::Storage::DataStore::Error &error) {
22 SinkWarning() << "Error while writing value" << error;
23 });
22} 24}
23 25
24void Index::remove(const QByteArray &key, const QByteArray &value) 26void Index::remove(const QByteArray &key, const QByteArray &value)
25{ 27{
26 mDb.remove(key, value); 28 mDb.remove(key, value, [&] (const Sink::Storage::DataStore::Error &error) {
29 SinkWarning() << "Error while removing value: " << key << value << error << error.store;
30 });
27} 31}
28 32
29void Index::lookup(const QByteArray &key, const std::function<void(const QByteArray &value)> &resultHandler, const std::function<void(const Error &error)> &errorHandler, bool matchSubStringKeys) 33void Index::lookup(const QByteArray &key, const std::function<void(const QByteArray &value)> &resultHandler, const std::function<void(const Error &error)> &errorHandler, bool matchSubStringKeys)
30{ 34{
31 mDb.scan(key, 35 mDb.scan(key,
32 [this, resultHandler](const QByteArray &key, const QByteArray &value) -> bool { 36 [&](const QByteArray &key, const QByteArray &value) -> bool {
33 resultHandler(value); 37 resultHandler(value);
34 return true; 38 return true;
35 }, 39 },
36 [this, errorHandler](const Sink::Storage::DataStore::Error &error) { 40 [&](const Sink::Storage::DataStore::Error &error) {
37 SinkWarning() << "Error while retrieving value" << error.message; 41 SinkWarning() << "Error while retrieving value" << error.message;
38 errorHandler(Error(error.store, error.code, error.message)); 42 errorHandler(Error(error.store, error.code, error.message));
39 }, 43 },
@@ -44,6 +48,6 @@ QByteArray Index::lookup(const QByteArray &key)
44{ 48{
45 QByteArray result; 49 QByteArray result;
46 //We have to create a deep copy, otherwise the returned data may become invalid when the transaction ends. 50 //We have to create a deep copy, otherwise the returned data may become invalid when the transaction ends.
47 lookup(key, [&result](const QByteArray &value) { result = QByteArray(value.constData(), value.size()); }, [this](const Index::Error &error) { SinkWarning() << "Error while retrieving value" << error.message; }); 51 lookup(key, [&](const QByteArray &value) { result = QByteArray(value.constData(), value.size()); }, [this](const Index::Error &error) { SinkWarning() << "Error while retrieving value" << error.message; });
48 return result; 52 return result;
49} 53}