Add source code.
This commit is contained in:
1 parent
dab19ace02
commit
0b8a7b3cdc
31 files changed
+2809
No files matched your search
@@ -0,0 +1,59 @@
|
||||
#pragma once
|
||||
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "Models.h"
|
||||
|
||||
struct sqlite3;
|
||||
|
||||
// Works on an in-memory SQLite database that is loaded from, and saved to, a
|
||||
// file on request (db save / backup / restore).
|
||||
class Database {
|
||||
public:
|
||||
Database();
|
||||
~Database();
|
||||
Database(const Database&) = delete;
|
||||
Database& operator=(const Database&) = delete;
|
||||
|
||||
// Loads `path` into memory if it exists, otherwise starts empty.
|
||||
void open(const std::string& path);
|
||||
void save();
|
||||
std::string backup(const std::string& file); // empty = timestamped name; returns the file used
|
||||
void restore(const std::string& file);
|
||||
|
||||
bool dirty() const;
|
||||
const std::string& path() const;
|
||||
|
||||
// Accounts
|
||||
std::optional<std::string> findAccount(const std::string& name) const; // canonical spelling
|
||||
std::vector<std::string> listAccounts() const;
|
||||
void addAccount(const std::string& name);
|
||||
void removeAccount(const std::string& name);
|
||||
void renameAccount(const std::string& name, const std::string& newName);
|
||||
|
||||
// Tasks
|
||||
std::optional<std::string> findTask(const std::string& name) const; // canonical spelling
|
||||
std::optional<TaskRow> getTask(const std::string& name) const;
|
||||
std::vector<TaskRow> listTasks() const;
|
||||
void addTask(const std::string& name, const std::optional<std::string>& account, const std::string& status);
|
||||
void removeTask(const std::string& name);
|
||||
void renameTask(const std::string& name, const std::string& newName);
|
||||
void setTaskAccount(const std::string& name, const std::optional<std::string>& account);
|
||||
void setTaskStatus(const std::string& name, const std::string& status);
|
||||
void setTaskNotes(const std::string& name, const std::string& notes);
|
||||
|
||||
private:
|
||||
using Param = std::optional<std::string>;
|
||||
using Row = std::vector<std::optional<std::string>>;
|
||||
|
||||
void createSchema();
|
||||
void exec(const std::string& sql);
|
||||
std::vector<Row> query(const std::string& sql, const std::vector<Param>& params = {}) const;
|
||||
void run(const std::string& sql, const std::vector<Param>& params);
|
||||
|
||||
sqlite3* db_;
|
||||
std::string path_;
|
||||
bool dirty_;
|
||||
};
|
||||
Reference in new issue
Block a user