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 @@ -60,6 +60,9 @@ virtual void clearNotifyToken() const = 0; virtual void setCurrentUserID(std::string userID) const = 0; virtual std::string getCurrentUserID() const = 0; + virtual void setMetadata(std::string entry_name, std::string data) const = 0; + virtual void clearMetadata(std::string entry_name) const = 0; + virtual std::string getMetadata(std::string entry_name) const = 0; virtual void clearSensitiveData() 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 @@ -60,6 +60,9 @@ void clearNotifyToken() const override; void setCurrentUserID(std::string userID) const override; std::string getCurrentUserID() const override; + void setMetadata(std::string entry_name, std::string data) const override; + void clearMetadata(std::string entry_name) const override; + std::string getMetadata(std::string entry_name) const override; void clearSensitiveData() 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 @@ -878,30 +878,38 @@ } void SQLiteQueryExecutor::setNotifyToken(std::string token) const { - Metadata entry{ - "notify_token", - token, - }; - SQLiteQueryExecutor::getStorage().replace(entry); + setMetadata("notify_token", token); } void SQLiteQueryExecutor::clearNotifyToken() const { - SQLiteQueryExecutor::getStorage().remove("notify_token"); + clearMetadata("notify_token"); } void SQLiteQueryExecutor::setCurrentUserID(std::string userID) const { + setMetadata("current_user_id", userID); +} + +std::string SQLiteQueryExecutor::getCurrentUserID() const { + return getMetadata("current_user_id"); +} + +void SQLiteQueryExecutor::setMetadata(std::string entry_name, std::string data) + const { Metadata entry{ - "current_user_id", - userID, + entry_name, + data, }; SQLiteQueryExecutor::getStorage().replace(entry); } -std::string SQLiteQueryExecutor::getCurrentUserID() const { - std::unique_ptr currentUserID = - SQLiteQueryExecutor::getStorage().get_pointer( - "current_user_id"); - return (currentUserID == nullptr) ? "" : currentUserID->data; +void SQLiteQueryExecutor::clearMetadata(std::string entry_name) const { + SQLiteQueryExecutor::getStorage().remove(entry_name); +} + +std::string SQLiteQueryExecutor::getMetadata(std::string entry_name) const { + std::unique_ptr entry = + SQLiteQueryExecutor::getStorage().get_pointer(entry_name); + return (entry == nullptr) ? "" : entry->data; } void SQLiteQueryExecutor::clearSensitiveData() const {