Files
chookchat/server/src/db.h

46 lines
964 B
C
Raw Normal View History

2026-07-20 10:57:07 +10:00
#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);
2026-07-20 19:02:04 +10:00
void addLike(uint64_t postId, uint64_t userId);
2026-07-20 10:57:07 +10:00
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