budget/src/database.h

76 lines
2.1 KiB
C
Raw Normal View History

//
// Created by quentin on 1/18/23.
//
#ifndef BUDGET_DATABASE_H
#define BUDGET_DATABASE_H
#include <string>
#include <sqlite3.h>
class Database {
public:
/**
* @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
*/
static bool doesAccountExist(const std::string &account, sqlite3 *db);
/**
* @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
*/
static void deleteAccount(const std::string &account, sqlite3 *db);
2023-01-22 17:05:29 -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);
/**
* @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);
};
#endif //BUDGET_DATABASE_H