Fork of Tangara with customizations
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tangara-fw/src/database/include/database.hpp

52 lines
971 B

2 years ago
#pragma once
#include <string>
2 years ago
#include <memory>
#include <optional>
2 years ago
#include "leveldb/cache.h"
#include "leveldb/db.h"
#include "leveldb/iterator.h"
2 years ago
#include "result.hpp"
namespace database {
class Iterator;
2 years ago
class Database {
public:
enum DatabaseError {
FAILED_TO_OPEN,
};
static auto Open() -> cpp::result<Database*, DatabaseError>;
~Database();
auto Initialise() -> void;
auto ByTitle() -> Iterator;
Database(const Database&) = delete;
Database& operator=(const Database&) = delete;
2 years ago
private:
std::unique_ptr<leveldb::DB> db_;
std::unique_ptr<leveldb::Cache> cache_;
Database(leveldb::DB* db, leveldb::Cache* cache);
};
class Iterator {
public:
explicit Iterator(leveldb::Iterator *it) : it_(it) {}
auto Next() -> std::optional<std::string>;
Iterator(const Iterator&) = delete;
Iterator& operator=(const Iterator&) = delete;
private:
std::unique_ptr<leveldb::Iterator> it_;
};
2 years ago
} // namespace database