summaryrefslogtreecommitdiffhomepage
path: root/storage.h
blob: 24f296191c3da43e63b2967e8a3d2b9ed7bb5e01 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#pragma once

#include <memory>
#include <string>
#include <tuple>

#include <SQLiteCpp/SQLiteCpp.h>

#include "config.h"

class Storage
{
public:
 Storage(const Config& config);
 ~Storage();

 uint64_t getNumberOfDocuments();
 bool exists(const std::string& id);

 std::string getDocument(const std::string& id);
 int getRevision(const std::string& id);
 int getCursorPos(const std::string& id);
 std::tuple<std::string, int, int> getRow(const std::string& id);
 
 void setDocument(const std::string& id, const std::string& document);
 void setRevision(const std::string& id, int rev);
 void setCursorPos(const std::string& id, int cursorPos);
 void setRow(const std::string& id, const std::string& document, int rev, int cursorPos);

 void cleanup();

private:
 SQLite::Database m_db;
 uint64_t m_maxage;

 // shared_ptr to work around initialization in constructor
 std::shared_ptr<SQLite::Statement> m_stmt_create;
 std::shared_ptr<SQLite::Statement> m_stmt_getNumberOfDocuments;
 std::shared_ptr<SQLite::Statement> m_stmt_cleanup;
 std::shared_ptr<SQLite::Statement> m_stmt_exists;
 std::shared_ptr<SQLite::Statement> m_stmt_getDocument;
 std::shared_ptr<SQLite::Statement> m_stmt_getRevision;
 std::shared_ptr<SQLite::Statement> m_stmt_getCursorPos;
 std::shared_ptr<SQLite::Statement> m_stmt_getRow;
 std::shared_ptr<SQLite::Statement> m_stmt_setDocument;
 std::shared_ptr<SQLite::Statement> m_stmt_setDocument_new;
 std::shared_ptr<SQLite::Statement> m_stmt_setRevision;
 std::shared_ptr<SQLite::Statement> m_stmt_setCursorPos;
 std::shared_ptr<SQLite::Statement> m_stmt_setRow;
};