Files
spark/src/lib/persistence/SqliteStore.h
T
John Colvin bd8c97244a refactor: Return row id in IStore::retrieve_one
This is a prerequisite to synchronizing security ids stored via IDGenerator
(the "new" way to store ids, added when we implemented Deribit), and
SecurityDB (the original way from spark days). The problem was that these
2 implementations were using separate databases. We need to unify the
interfaces between these storage services to avoid breaking existing code.
2024-11-20 22:17:08 +00:00

55 lines
1.4 KiB
C++

#pragma once
#include "IStore.h"
#include "lib/persistence/store_row.h"
#include "lib/utils/Sqlite_utils.h"
#include <cstdint>
#include <memory>
#include <vector>
namespace bts {
namespace persistence {
class SqliteStore : public IStore {
public:
SqliteStore(std::string const &db);
explicit SqliteStore(sqlite3_ptr db);
~SqliteStore();
static SqliteStore from_path(const std::string &full_path);
typedef std::map<std::string, std::map<std::string, std::string>> Data;
Data retrieve_all() override;
std::tuple<bool, std::int64_t, std::string> retrieve_one(
std::string const &ns, std::string const &k) override;
void remove(
std::string const &ns, std::set<std::string> const &keys) override;
void remove_all(std::string const &ns) override;
std::int64_t insert(
std::string const &ns,
std::string const &k,
std::string const &v) override;
void insert_many(const std::vector<StoreRow> &rows);
void insert_many_resolve_ids(std::vector<StoreRow> &rows);
void update(
std::string const &ns,
std::string const &k,
std::string const &v) override;
// usefull for unit testing
static std::string storage_location(std::string const &db);
private:
SqliteStore();
struct PImpl;
std::unique_ptr<PImpl> me;
void init_db();
};
} // namespace persistence
} // namespace bts