yay initial commit
This commit is contained in:
44
server/src/db.h
Normal file
44
server/src/db.h
Normal file
@@ -0,0 +1,44 @@
|
||||
#ifndef DB_H
|
||||
#define DB_H
|
||||
|
||||
#include <cstdint>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <sqlite3.h>
|
||||
#include <vector>
|
||||
|
||||
#include "post.h"
|
||||
|
||||
struct User {
|
||||
uint64_t id = 0;
|
||||
std::string name = "";
|
||||
std::string passwordHash = "";
|
||||
|
||||
User(uint64_t id, const std::string& name, const std::string& passwordHash) :
|
||||
id(id), name(name), passwordHash(passwordHash) {}
|
||||
};
|
||||
|
||||
class Database {
|
||||
|
||||
sqlite3* db;
|
||||
|
||||
public:
|
||||
Database() = delete;
|
||||
Database(const std::string& path);
|
||||
|
||||
~Database();
|
||||
|
||||
std::optional<Post> getPost(uint64_t id);
|
||||
std::vector<Post> getUserPosts(uint64_t userId);
|
||||
std::vector<Post> getTopPosts(uint64_t amount);
|
||||
void addPost(const Post& post);
|
||||
|
||||
std::optional<User> getUser(uint64_t id);
|
||||
std::optional<User> getUserByName(const std::string& name);
|
||||
|
||||
// this will modify the user to have their user ID
|
||||
void addUser(User& user);
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user