44 lines
1.2 KiB
C++
44 lines
1.2 KiB
C++
#ifndef DATABASE_HPP
|
|
#define DATABASE_HPP
|
|
|
|
#include <filesystem>
|
|
#include <string>
|
|
#include <json.hpp>
|
|
|
|
typedef struct sqlite3 sqlite3;
|
|
|
|
namespace simple_object_storage {
|
|
|
|
class dbEntry {
|
|
public:
|
|
std::string label_tag; // unique identifier for the object
|
|
std::string hash; // hash of the object - not unique
|
|
nlohmann::json metadata;
|
|
};
|
|
|
|
class Database {
|
|
public:
|
|
static const int CURRENT_VERSION = 1;
|
|
|
|
Database(const std::filesystem::path& path);
|
|
~Database();
|
|
bool insert(const dbEntry& entry);
|
|
bool remove(const std::string& label_tag);
|
|
bool remove_by_hash(const std::string& hash);
|
|
bool get(const std::string& label_tag, dbEntry& entry);
|
|
bool update(const std::string& label_tag, const dbEntry& entry);
|
|
bool list(std::vector<dbEntry>& entries);
|
|
bool update_or_insert(const dbEntry& entry);
|
|
private:
|
|
std::filesystem::path path_;
|
|
sqlite3* db_;
|
|
|
|
bool createVersionTable();
|
|
bool getVersion(int& version);
|
|
bool setVersion(int version);
|
|
bool migrate(int from_version, int to_version);
|
|
};
|
|
|
|
} // namespace simple_object_storage
|
|
|
|
#endif // DATABASE_HPP
|