2023-01-21 17:50:07 -06:00
|
|
|
//
|
|
|
|
// Created by quentin on 1/18/23.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef BUDGET_DATABASE_H
|
|
|
|
#define BUDGET_DATABASE_H
|
|
|
|
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <sqlite3.h>
|
|
|
|
|
|
|
|
class Database {
|
|
|
|
public:
|
2023-01-22 17:21:31 -06:00
|
|
|
/**
|
|
|
|
* @brief Checks if an account exists in the database
|
|
|
|
*
|
|
|
|
* @param account The name of the account to check for
|
|
|
|
* @param db The database connection to use
|
|
|
|
*
|
|
|
|
* @return True if the account exists, false otherwise
|
|
|
|
*
|
|
|
|
* @throws std::runtime_error If the database query fails
|
|
|
|
*/
|
2023-01-21 17:50:07 -06:00
|
|
|
static bool doesAccountExist(const std::string &account, sqlite3 *db);
|
2023-01-21 18:27:03 -06:00
|
|
|
|
2023-01-22 17:21:31 -06:00
|
|
|
/**
|
|
|
|
* @brief Deletes an account from the database
|
|
|
|
*
|
|
|
|
* @param account The name of the account to delete
|
|
|
|
* @param db The database connection to use
|
|
|
|
*
|
|
|
|
* @return True if the account was successfully deleted, false otherwise
|
|
|
|
*
|
|
|
|
* @throws std::runtime_error If the database query fails
|
|
|
|
*/
|
2023-01-22 18:09:30 -06:00
|
|
|
static void deleteAccount(const std::string &account, sqlite3 *db);
|
2023-01-22 17:05:29 -06:00
|
|
|
|
2023-01-22 17:21:31 -06:00
|
|
|
/**
|
|
|
|
* @brief Retrieves the cached value of an account from the database
|
|
|
|
*
|
|
|
|
* @param account The name of the account to retrieve the value of
|
|
|
|
* @param db The database connection to use
|
|
|
|
*
|
|
|
|
* @return The cached value of the account
|
|
|
|
*
|
|
|
|
* @throws std::runtime_error If the database query fails or the account doesn't exist
|
|
|
|
*/
|
2023-01-22 17:05:29 -06:00
|
|
|
static double getValue(const std::string &account, sqlite3 *db);
|
|
|
|
|
2023-01-22 17:21:31 -06:00
|
|
|
/**
|
|
|
|
* @brief Caches the value of an account by calculating the sum of all payments and earnings
|
|
|
|
*
|
|
|
|
* @param accountId The ID of the account to cache the value of
|
|
|
|
* @param db The database connection to use
|
|
|
|
*
|
|
|
|
* @return The cached value of the account
|
|
|
|
*
|
|
|
|
* @throws std::runtime_error If the database query fails
|
|
|
|
*/
|
2023-01-22 17:05:29 -06:00
|
|
|
static double cacheAccountValue(long long accountId, sqlite3 *db);
|
2023-01-26 18:54:38 -06:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Sets a new description for an account
|
|
|
|
*
|
|
|
|
* @param account The account name
|
|
|
|
* @param description The new description
|
|
|
|
* @param db The database connection to use
|
|
|
|
*
|
|
|
|
* @throws std::runtime_error If the statement fails to prepare or the step fails to execute
|
|
|
|
*/
|
|
|
|
static void accountDescription(const std::string& account, const std::string& description, sqlite3 *db);
|
2023-01-21 17:50:07 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif //BUDGET_DATABASE_H
|