From c9fa963e71258c5adfb71cf1996cd1bcb33df0bb Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Sun, 26 Feb 2023 08:54:17 +0100 Subject: Start with copy of whiteboard --- storage.h | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 storage.h (limited to 'storage.h') diff --git a/storage.h b/storage.h new file mode 100644 index 0000000..131b786 --- /dev/null +++ b/storage.h @@ -0,0 +1,64 @@ +#pragma once + +#include +#include +#include + +#include + +#include "config.h" +#include "compiledsql.h" + +class Storage +{ +public: + Storage(const Config& config); + ~Storage(); + + uint64_t getNumberOfDocuments(); + uint64_t dbsize_gross(); + uint64_t dbsize_net(); + 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 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 touchDocument(const std::string& id); + + void cleanup(); + + std::string generate_id(); + +private: + SQLite::Database m_db; + uint64_t m_maxage; + + // shared_ptr to work around initialization in constructor + CompiledSQL m_stmt_create; + CompiledSQL m_stmt_getNumberOfDocuments; + CompiledSQL m_stmt_cleanup; + CompiledSQL m_stmt_vacuum; + CompiledSQL m_stmt_exists; + CompiledSQL m_stmt_getDocument; + CompiledSQL m_stmt_getRevision; + CompiledSQL m_stmt_getCursorPos; + CompiledSQL m_stmt_getRow; + CompiledSQL m_stmt_setDocument; + CompiledSQL m_stmt_setDocument_new; + CompiledSQL m_stmt_setRevision; + CompiledSQL m_stmt_setCursorPos; + CompiledSQL m_stmt_setRow; + CompiledSQL m_stmt_getDbSizeGross; + CompiledSQL m_stmt_getDbSizeNet; + CompiledSQL m_stmt_touchDocument; +}; + +uint32_t checksum32(const std::string& s); + -- cgit v1.2.3