Skip to content

Commit

Permalink
[native] add entity and methods for redux-persist storage
Browse files Browse the repository at this point in the history
Summary:
Mapping web methods: [storage-engine-queries](https://github.com/CommE2E/comm/blob/8d63c6591600a98dcdf3458ed0cc858de11bf9b8/web/database/queries/storage-engine-queries.js)

Depends on D8471

Test Plan: Tests from D8557

Reviewers: michal, tomek

Reviewed By: michal

Subscribers: ashoat

Differential Revision: https://phab.comm.dev/D8472
  • Loading branch information
xsanm committed Jul 21, 2023
1 parent bf8a921 commit 6d72d08
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 1 deletion.
5 changes: 5 additions & 0 deletions native/cpp/CommonCpp/DatabaseManagers/DatabaseQueryExecutor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -66,6 +67,10 @@ class DatabaseQueryExecutor {
virtual void removeReports(const std::vector<std::string> &ids) const = 0;
virtual void removeAllReports() const = 0;
virtual std::vector<Report> 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;
Expand Down
28 changes: 27 additions & 1 deletion native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -930,7 +930,13 @@ auto &SQLiteQueryExecutor::getStorage() {
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;
}
Expand Down Expand Up @@ -1174,6 +1180,26 @@ std::vector<Report> SQLiteQueryExecutor::getAllReports() const {
return SQLiteQueryExecutor::getStorage().get_all<Report>();
}

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<PersistItem>(key);
}

std::string SQLiteQueryExecutor::getPersistStorageItem(std::string key) const {
std::unique_ptr<PersistItem> entry =
SQLiteQueryExecutor::getStorage().get_pointer<PersistItem>(key);
return (entry == nullptr) ? "" : entry->item;
}

void SQLiteQueryExecutor::beginTransaction() const {
SQLiteQueryExecutor::getStorage().begin_transaction();
}
Expand Down
3 changes: 3 additions & 0 deletions native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ class SQLiteQueryExecutor : public DatabaseQueryExecutor {
void removeReports(const std::vector<std::string> &ids) const override;
void removeAllReports() const override;
std::vector<Report> 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;
Expand Down
12 changes: 12 additions & 0 deletions native/cpp/CommonCpp/DatabaseManagers/entities/PersistItem.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma once

#include <string>

namespace comm {

struct PersistItem {
std::string key;
std::string item;
};

} // namespace comm

0 comments on commit 6d72d08

Please sign in to comment.