#include "session.h"

Session::Session(QObject *parent) : QObject(parent)
{

}

Session::~Session() {
    unload();
}


void Session::load(std::filesystem::path path)
{
    if(db) {
        unload();
    }
    auto rc = sqlite3_open(path.c_str(), &db);
    if(rc) {
        qDebug("cannot open database");
        qDebug() << sqlite3_errmsg(db);
        unload();
        throw;
    }
    // check if tables exist
    // create tables or add history
}

void Session::unload() {
    if(db) {
        sqlite3_close(db);
    }
}

void Session::saveRequest(json data) {
    // todo
}