2023-12-30 22:42:11 +00:00
|
|
|
//SPDX-FileCopyrightText: 2023 Yury Gubich <blue@macaw.me>
|
|
|
|
//SPDX-License-Identifier: GPL-3.0-or-later
|
2023-12-10 23:23:15 +00:00
|
|
|
|
2023-12-07 20:32:43 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <stdexcept>
|
2023-12-10 23:23:15 +00:00
|
|
|
#include <filesystem>
|
2023-12-11 23:29:55 +00:00
|
|
|
#include <optional>
|
2023-12-07 20:32:43 +00:00
|
|
|
|
|
|
|
#include <mysql.h>
|
|
|
|
|
2023-12-29 17:40:00 +00:00
|
|
|
#include "database/interface.h"
|
2023-12-10 23:23:15 +00:00
|
|
|
#include "utils/helpers.h"
|
2023-12-07 20:32:43 +00:00
|
|
|
|
2023-12-29 17:40:00 +00:00
|
|
|
namespace DB {
|
|
|
|
class MySQL : public Interface {
|
2023-12-08 22:26:16 +00:00
|
|
|
class Statement;
|
2023-12-20 22:42:13 +00:00
|
|
|
class Transaction;
|
2023-12-22 23:25:20 +00:00
|
|
|
|
|
|
|
|
2023-12-07 20:32:43 +00:00
|
|
|
public:
|
2024-01-11 21:33:46 +00:00
|
|
|
MySQL ();
|
|
|
|
~MySQL () override;
|
2023-12-07 20:32:43 +00:00
|
|
|
|
2024-01-11 21:33:46 +00:00
|
|
|
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;
|
2023-12-07 20:32:43 +00:00
|
|
|
|
2024-01-11 21:33:46 +00:00
|
|
|
void migrate (uint8_t targetVersion) override;
|
|
|
|
uint8_t getVersion () override;
|
|
|
|
void setVersion (uint8_t version) override;
|
2023-12-08 22:26:16 +00:00
|
|
|
|
2024-01-11 21:33:46 +00:00
|
|
|
unsigned int registerAccount (const std::string& login, const std::string& hash) override;
|
|
|
|
std::string getAccountHash (const std::string& login) override;
|
|
|
|
Session createSession (const std::string& login, const std::string& access, const std::string& renew) override;
|
|
|
|
Session findSession (const std::string& accessToken) override;
|
|
|
|
std::vector<Asset> listAssets (unsigned int owner) override;
|
2023-12-20 22:42:13 +00:00
|
|
|
|
2023-12-10 23:23:15 +00:00
|
|
|
private:
|
2024-01-11 21:33:46 +00:00
|
|
|
void executeFile (const std::filesystem::path& relativePath);
|
|
|
|
static std::optional<std::string> getComment (std::string& string);
|
|
|
|
unsigned int lastInsertedId ();
|
2023-12-10 23:23:15 +00:00
|
|
|
|
2023-12-07 20:32:43 +00:00
|
|
|
protected:
|
|
|
|
MYSQL connection;
|
|
|
|
std::string login;
|
|
|
|
std::string password;
|
|
|
|
std::string database;
|
2023-12-22 23:25:20 +00:00
|
|
|
|
|
|
|
struct ResDeleter {
|
|
|
|
void operator () (MYSQL_RES* res) {
|
|
|
|
mysql_free_result(res);
|
|
|
|
}
|
|
|
|
};
|
2023-12-07 20:32:43 +00:00
|
|
|
};
|
2023-12-29 17:40:00 +00:00
|
|
|
}
|