// // Created by quentin on 1/18/23. // #ifndef BUDGET_DATABASE_H #define BUDGET_DATABASE_H #include #include 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 bool deleteAccount(const std::string &account, sqlite3 *db); /** * @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 */ 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 */ static double cacheAccountValue(long long accountId, sqlite3 *db); }; #endif //BUDGET_DATABASE_H