#pragma once
#include <myapp/persistence/database.h>
#include <functional>
#include <memory>
#include <sqlite3.h>

namespace myapp::persistence {

class sqlite3_database : public database
{
public:
    sqlite3_database(std::string connection_string);

public:
    void create_readout_table_if_not_exists();
    void save_readout(std::string const& topic, std::string const& value) override;
    std::string last_readout(std::string const& topic) override;

    std::string dump();

private:
    void execute_query(std::string const&);
    void execute_query(std::string const& query, std::function<void(int, char**, char**)> callback);

private:
    class library_init;
    std::shared_ptr<library_init> library_init_;

private:
    std::shared_ptr<sqlite3> db_;
    std::shared_ptr<sqlite3_stmt> insert_readout_;
};

} /* namespace myapp::persistence */
