diff --git a/native/cpp/CommonCpp/DatabaseManagers/DatabaseQueryExecutor.h b/native/cpp/CommonCpp/DatabaseManagers/DatabaseQueryExecutor.h --- a/native/cpp/CommonCpp/DatabaseManagers/DatabaseQueryExecutor.h +++ b/native/cpp/CommonCpp/DatabaseManagers/DatabaseQueryExecutor.h @@ -7,6 +7,7 @@ #include "entities/MessageStoreThread.h" #include "entities/OlmPersistAccount.h" #include "entities/OlmPersistSession.h" +#include "entities/PersistItem.h" #include "entities/Report.h" #include "entities/Thread.h" @@ -66,6 +67,10 @@ virtual void removeReports(const std::vector &ids) const = 0; virtual void removeAllReports() const = 0; virtual std::vector getAllReports() const = 0; + virtual void + setPersistStorageItem(std::string key, std::string item) const = 0; + virtual void removePersistStorageItem(std::string key) const = 0; + virtual std::string getPersistStorageItem(std::string key) const = 0; virtual void beginTransaction() const = 0; virtual void commitTransaction() const = 0; virtual void rollbackTransaction() const = 0; diff --git a/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.h b/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.h --- a/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.h +++ b/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.h @@ -63,6 +63,9 @@ void removeReports(const std::vector &ids) const override; void removeAllReports() const override; std::vector getAllReports() const override; + void setPersistStorageItem(std::string key, std::string item) const override; + void removePersistStorageItem(std::string key) const override; + std::string getPersistStorageItem(std::string key) const override; void beginTransaction() const override; void commitTransaction() const override; void rollbackTransaction() const override; diff --git a/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.cpp b/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.cpp --- a/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.cpp +++ b/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.cpp @@ -930,7 +930,13 @@ make_table( "reports", make_column("id", &Report::id, unique(), primary_key()), - make_column("report", &Report::report))); + make_column("report", &Report::report)), + make_table( + "persist_storage", + make_column("key", &PersistItem::key, unique(), primary_key()), + make_column("item", &PersistItem::item)) + + ); storage.on_open = on_database_open; return storage; } @@ -1174,6 +1180,26 @@ return SQLiteQueryExecutor::getStorage().get_all(); } +void SQLiteQueryExecutor::setPersistStorageItem( + std::string key, + std::string item) const { + PersistItem entry{ + key, + item, + }; + SQLiteQueryExecutor::getStorage().replace(entry); +} + +void SQLiteQueryExecutor::removePersistStorageItem(std::string key) const { + SQLiteQueryExecutor::getStorage().remove(key); +} + +std::string SQLiteQueryExecutor::getPersistStorageItem(std::string key) const { + std::unique_ptr entry = + SQLiteQueryExecutor::getStorage().get_pointer(key); + return (entry == nullptr) ? "" : entry->item; +} + void SQLiteQueryExecutor::beginTransaction() const { SQLiteQueryExecutor::getStorage().begin_transaction(); } diff --git a/native/cpp/CommonCpp/DatabaseManagers/entities/PersistItem.h b/native/cpp/CommonCpp/DatabaseManagers/entities/PersistItem.h new file mode 100644 --- /dev/null +++ b/native/cpp/CommonCpp/DatabaseManagers/entities/PersistItem.h @@ -0,0 +1,12 @@ +#pragma once + +#include + +namespace comm { + +struct PersistItem { + std::string key; + std::string item; +}; + +} // namespace comm