GitWatcherBot  1.0.0
A Telegram Bot that notifies you when a new change is made in your repositories (issues, pull requests, stars, forks, and watches)
All Classes Namespaces Files Functions Variables Typedefs Macros
Database Class Reference

#include <Database.hpp>

Static Public Member Functions

static std::mutex & getDbMutex () noexcept
 Returns Database mutex to be used by multiple threads for writing/reading into/from the database.
More...
 
static auto & getStorage ()
 Returns create database storage. It creates it if not already created, also syncs the db schema.
More...
 
static void backup ()
 Call this periodically to backup the database in res/DbBackups/ periodically. More...
 
static bool userExists (const models::UserId userId)
 Returns true if User with id exists in the database. More...
 
static models::User getUser (const models::UserId userId)
 Returns User object by id. More...
 
static void addUser (const models::User &newUser)
 Adds a new user to the database. More...
 
static models::UserStatus getUserStatus (const models::UserId userId)
 Returns UserStatus by id. More...
 
static void updateUserStatus (const models::UserId userId, const models::UserStatus newStatus)
 Update User's status by id. More...
 
static void updateUser (const models::User &updatedUser)
 Updates existing user changed properties. More...
 
static int userReposCount (const models::UserId userId)
 Returns the count of repositories this user is watching. More...
 
static bool repoExists (const models::RepositoryId repoId)
 Returns true if a Repository exists with same id. More...
 
static bool repoExistsByFullName (const std::string &full_name)
 Returns true if Repository exists with same full_name (example: "torvalds/linux") More...
 
static void addRepo (const models::Repository &newRepo)
 Adds a new Repository object to the database. More...
 
static void updateRepo (const models::Repository &updatedRepo)
 Updates existing repository changed properties. More...
 
static void removeUserRepo (const models::UserId watcherId, const models::RepositoryId repoId)
 Removes Repository from User's watch list. More...
 
static void iterateRepos (const std::function< void(const models::Repository &)> &callback)
 Lock secure iterate over repositories to not hold the db mutex for a long time. More...
 
static std::vector< std::string > getUserReposFullnames (const models::UserId watcherId)
 Returns full names of all repositories that a User is watching. More...
 
static std::vector< models::RepositorygetUserRepos (const models::UserId watcherId)
 Returns all Repositories objects that a User is watching. More...
 
static std::int64_t addLog (const models::Log &newLog)
 Adds a new Log object to the database. More...
 

Detailed Description

Definition at line 14 of file Database.hpp.

Member Function Documentation

◆ addLog()

static std::int64_t Database::addLog ( const models::Log newLog)
static

Adds a new Log object to the database.

◆ addRepo()

static void Database::addRepo ( const models::Repository newRepo)
static

Adds a new Repository object to the database.

◆ addUser()

static void Database::addUser ( const models::User newUser)
static

Adds a new user to the database.

◆ backup()

static void Database::backup ( )
static

Call this periodically to backup the database in res/DbBackups/ periodically.

◆ getDbMutex()

static std::mutex& Database::getDbMutex ( )
staticnoexcept

Returns Database mutex to be used by multiple threads for writing/reading into/from the database.

◆ getStorage()

static auto& Database::getStorage ( )
inlinestatic

Returns create database storage. It creates it if not already created, also syncs the db schema.

Definition at line 26 of file Database.hpp.

◆ getUser()

static models::User Database::getUser ( const models::UserId  userId)
static

Returns User object by id.

Note
Call userExists() first before calling this function

◆ getUserRepos()

static std::vector<models::Repository> Database::getUserRepos ( const models::UserId  watcherId)
static

Returns all Repositories objects that a User is watching.

◆ getUserReposFullnames()

static std::vector<std::string> Database::getUserReposFullnames ( const models::UserId  watcherId)
static

Returns full names of all repositories that a User is watching.

◆ getUserStatus()

static models::UserStatus Database::getUserStatus ( const models::UserId  userId)
static

Returns UserStatus by id.

◆ iterateRepos()

static void Database::iterateRepos ( const std::function< void(const models::Repository &)> &  callback)
static

Lock secure iterate over repositories to not hold the db mutex for a long time.

Note
Use this instead of getStorage().iterate<Repository>()

◆ removeUserRepo()

static void Database::removeUserRepo ( const models::UserId  watcherId,
const models::RepositoryId  repoId 
)
static

Removes Repository from User's watch list.

◆ repoExists()

static bool Database::repoExists ( const models::RepositoryId  repoId)
static

Returns true if a Repository exists with same id.

◆ repoExistsByFullName()

static bool Database::repoExistsByFullName ( const std::string &  full_name)
static

Returns true if Repository exists with same full_name (example: "torvalds/linux")

◆ updateRepo()

static void Database::updateRepo ( const models::Repository updatedRepo)
static

Updates existing repository changed properties.

◆ updateUser()

static void Database::updateUser ( const models::User updatedUser)
static

Updates existing user changed properties.

◆ updateUserStatus()

static void Database::updateUserStatus ( const models::UserId  userId,
const models::UserStatus  newStatus 
)
static

Update User's status by id.

◆ userExists()

static bool Database::userExists ( const models::UserId  userId)
static

Returns true if User with id exists in the database.

◆ userReposCount()

static int Database::userReposCount ( const models::UserId  userId)
static

Returns the count of repositories this user is watching.


The documentation for this class was generated from the following file: