2019-09-30 00:34:56 +00:00
|
|
|
#pragma once
|
|
|
|
|
2019-10-03 22:43:39 +00:00
|
|
|
#include "cache.h"
|
|
|
|
#include "api.h"
|
|
|
|
|
2019-09-30 00:34:56 +00:00
|
|
|
#include <string>
|
2020-06-02 22:24:54 +00:00
|
|
|
#include <map>
|
2019-09-30 00:34:56 +00:00
|
|
|
#include <nlohmann/json_fwd.hpp>
|
|
|
|
|
|
|
|
typedef struct sqlite3 sqlite3;
|
|
|
|
typedef struct sqlite3_stmt sqlite3_stmt;
|
|
|
|
class Okapi;
|
|
|
|
|
|
|
|
using json = nlohmann::json;
|
|
|
|
|
2019-10-03 22:43:39 +00:00
|
|
|
class OCdb : public Api {
|
2019-09-30 00:34:56 +00:00
|
|
|
private:
|
|
|
|
sqlite3* db;
|
2020-02-11 16:34:23 +00:00
|
|
|
mutable sqlite3_stmt* stmt;
|
2019-10-06 00:46:07 +00:00
|
|
|
int revision;
|
2019-09-30 00:34:56 +00:00
|
|
|
|
2020-02-11 16:34:23 +00:00
|
|
|
bool request(const std::string& req) const;
|
|
|
|
bool init_part(const std::string& json_file); // read db dump
|
|
|
|
bool parse_item(const json& j);
|
|
|
|
bool update_cache(const json& j);
|
|
|
|
bool update_log(const json& j);
|
2019-09-30 23:48:49 +00:00
|
|
|
bool read_revision();
|
2019-11-04 20:44:08 +00:00
|
|
|
|
2019-09-30 00:34:56 +00:00
|
|
|
public:
|
2020-02-11 16:34:23 +00:00
|
|
|
explicit OCdb(const std::string& db_file);
|
2019-09-30 00:34:56 +00:00
|
|
|
~OCdb();
|
|
|
|
|
2020-07-06 15:15:53 +00:00
|
|
|
bool init(const std::string& dump_path); // read db dump
|
2020-02-11 16:34:23 +00:00
|
|
|
bool update(const Okapi& oc); // apply changelog
|
|
|
|
int get_revision() const;
|
2019-10-06 00:46:07 +00:00
|
|
|
void set_revision(int rev);
|
2019-10-03 22:43:39 +00:00
|
|
|
|
2020-02-11 16:34:23 +00:00
|
|
|
Caches get_user_caches_not_found(const std::string& uuid) const;
|
2020-02-11 16:37:01 +00:00
|
|
|
Caches get_user_caches(const std::string& uuid, int count = 0) const override;
|
2020-06-02 22:24:54 +00:00
|
|
|
std::map<std::string, int> get_region_stats();
|
2019-09-30 00:34:56 +00:00
|
|
|
};
|