i'd say this is too easy but i know damn well implementing networking & multithreading is going to take my fucking soul

This commit is contained in:
Xory 2025-09-25 20:13:47 +03:00
parent 60afa6126f
commit 348c353dac
2 changed files with 13 additions and 7 deletions

View file

@ -6,5 +6,5 @@ And also my first serious C++ project.
## Roadmap
- [X] Basic K/V store
- [X] Remove/add entries
- [ ] Serialisation and saving
- [X] Serialisation and saving
- [ ] Networking

View file

@ -14,6 +14,14 @@ void save_database(Db& database, std::string file_name) {
db_file.close();
}
void load_database(Db& database, std::string file_name) {
std::ifstream db_file(file_name);
std::string raw_file_text;
db_file >> raw_file_text;
db_file.close();
database = nlohmann::json::parse(raw_file_text);
}
void add_entry(Db& database, std::string key, std::string value) {
database.push_back({key, value});
}
@ -45,6 +53,10 @@ void prompt_user(Db& database) {
std::string file;
std::cin >> file;
save_database(database, file);
} else if (mode == "load") {
std::string file;
std::cin >> file;
load_database(database, file);
} else {
prompt_user(database);
}
@ -52,12 +64,6 @@ void prompt_user(Db& database) {
int main() {
Db database;
database = {
{ "name", "username" },
{ "john", "unwanted_guest"},
{ "laith", "ducc" }
};
while (true) {
for (std::vector entry: database) {