68 lines
2.0 KiB
C++
68 lines
2.0 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/interface.h"
|
|
#include "utils/helpers.h"
|
|
|
|
namespace DB {
|
|
class MySQL : public Interface {
|
|
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;
|
|
|
|
uint32_t 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 (uint32_t owner) override;
|
|
Asset addAsset (const Asset& asset) override;
|
|
void updateAsset (const Asset& asset) override;
|
|
bool deleteAsset(uint32_t assetId, uint32_t actorId) override;
|
|
|
|
std::vector<Currency> listUsedCurrencies(uint32_t owner) override;
|
|
|
|
DB::Transaction addTransaction(const DB::Transaction& transaction) override;
|
|
void updateTransaction(const DB::Transaction& transaction) override;
|
|
std::vector<DB::Transaction> listTransactions(uint32_t owner) override;
|
|
|
|
private:
|
|
void executeFile (const std::filesystem::path& relativePath);
|
|
bool getBlock (std::ifstream& file, std::string& block, std::string& name);
|
|
uint32_t lastInsertedId ();
|
|
|
|
protected:
|
|
MYSQL connection;
|
|
std::string login;
|
|
std::string password;
|
|
std::string database;
|
|
|
|
struct ResDeleter {
|
|
void operator () (MYSQL_RES* res) {
|
|
mysql_free_result(res);
|
|
}
|
|
};
|
|
};
|
|
}
|