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

73 lines
1.8 KiB
C
Raw Normal View History

// SPDX-FileCopyrightText: 2023 Yury Gubich <blue@macaw.me>
// SPDX-License-Identifier: GPL-3.0-or-later
2023-12-07 20:32:43 +00:00
#pragma once
#include <stdexcept>
#include <string>
#include <memory>
#include <vector>
#include <cstdint>
2023-12-07 20:32:43 +00:00
2023-12-29 17:40:00 +00:00
namespace DB {
struct Session {
unsigned int id;
unsigned int owner;
std::string accessToken;
std::string renewToken;
};
struct Asset {
unsigned int id;
unsigned int owner;
unsigned int currency;
std::string title;
std::string icon;
// `color` INTEGER UNSIGNED DEFAULT 0,
// `balance` DECIMAL (20, 5) DEFAULT 0,
// `type` INTEGER UNSIGNED NOT NULL,
bool archived;
};
2023-12-29 17:40:00 +00:00
class Interface {
2023-12-07 20:32:43 +00:00
public:
enum class Type {
mysql
};
enum class State {
disconnected,
connecting,
connected
};
2023-12-29 17:40:00 +00:00
static std::unique_ptr<Interface> create(Type type);
2023-12-07 20:32:43 +00:00
2023-12-29 17:40:00 +00:00
virtual ~Interface();
2023-12-07 20:32:43 +00:00
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;
2023-12-08 22:26:16 +00:00
virtual uint8_t getVersion() = 0;
virtual void setVersion(uint8_t version) = 0;
2023-12-20 22:42:13 +00:00
virtual unsigned int registerAccount(const std::string& login, const std::string& hash) = 0;
2023-12-22 23:25:20 +00:00
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(unsigned int owner) = 0;
2023-12-20 22:42:13 +00:00
2023-12-07 20:32:43 +00:00
protected:
2023-12-29 17:40:00 +00:00
Interface(Type type);
2023-12-07 20:32:43 +00:00
protected:
State state;
};
2023-12-29 17:40:00 +00:00
}