1
0
forked from blue/pica
pica/database/interface.h

71 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 <string>
#include <memory>
#include <vector>
#include <cstdint>
#include "schema/session.h"
#include "schema/asset.h"
#include "schema/currency.h"
#include "schema/transaction.h"
namespace DB {
class Interface {
public:
enum class Type {
mysql
};
enum class State {
disconnected,
connecting,
connected
};
static std::unique_ptr<Interface> create(Type type);
virtual ~Interface();
State currentState() const;
const Type type;
public:
virtual void connect(const std::string& path) = 0;
virtual void disconnect() = 0;
virtual void setDatabase(const std::string& newDatabase) = 0;
virtual void setCredentials(const std::string& login, const std::string& password) = 0;
virtual void migrate(uint8_t targetVersion) = 0;
virtual uint8_t getVersion() = 0;
virtual void setVersion(uint8_t version) = 0;
virtual uint32_t registerAccount(const std::string& login, const std::string& hash) = 0;
virtual std::string getAccountHash(const std::string& login) = 0;
virtual Session createSession(const std::string& login, const std::string& access, const std::string& renew) = 0;
virtual Session findSession(const std::string& accessToken) = 0;
virtual std::vector<Asset> listAssets(uint32_t owner) = 0;
virtual Asset addAsset(const Asset& asset) = 0;
virtual void updateAsset(const Asset& asset) = 0;
virtual bool deleteAsset(uint32_t assetId, uint32_t actorId) = 0;
virtual std::vector<Currency> listUsedCurrencies(uint32_t owner) = 0;
virtual DB::Transaction addTransaction(const DB::Transaction& transaction) = 0;
virtual std::vector<DB::Transaction> listTransactions(uint32_t owner) = 0;
virtual void updateTransaction(const DB::Transaction& transaction) = 0;
virtual bool deleteTransaction(uint32_t id, uint32_t actorId) = 0;
protected:
Interface(Type type);
protected:
State state;
};
}