44 lines
1.1 KiB
C++
44 lines
1.1 KiB
C++
// SPDX-FileCopyrightText: 2023 Yury Gubich <blue@macaw.me>
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
#pragma once
|
|
|
|
#include <stdexcept>
|
|
#include <filesystem>
|
|
#include <optional>
|
|
|
|
#include <mysql.h>
|
|
|
|
#include "database/dbinterface.h"
|
|
#include "utils/helpers.h"
|
|
|
|
class MySQL : public DBInterface {
|
|
class Statement;
|
|
class Transaction;
|
|
public:
|
|
MySQL();
|
|
~MySQL() override;
|
|
|
|
void connect(const std::string& path) override;
|
|
void disconnect() override;
|
|
void setCredentials(const std::string& login, const std::string& password) override;
|
|
void setDatabase(const std::string& database) override;
|
|
|
|
void migrate(uint8_t targetVersion) override;
|
|
uint8_t getVersion() override;
|
|
void setVersion(uint8_t version) override;
|
|
|
|
unsigned int registerAccount(const std::string& login, const std::string& hash) override;
|
|
|
|
private:
|
|
void executeFile(const std::filesystem::path& relativePath);
|
|
static std::optional<std::string> getComment(std::string& string);
|
|
unsigned int lastInsertedId();
|
|
|
|
protected:
|
|
MYSQL connection;
|
|
std::string login;
|
|
std::string password;
|
|
std::string database;
|
|
};
|