Rehti MMORPG  1.0.0
Rehti MMORPG is a free and open source MMORPG game.
DatabaseManager Class Reference

Class for handling database queries. More...

#include <DatabaseManager.hpp>

Collaboration diagram for DatabaseManager:
Collaboration graph

Public Member Functions

 DatabaseManager ()
 
 ~DatabaseManager ()=default
 
int createConnection ()
 Create connection to the database. More...
 
PlayerTable loadPlayerDataFromDb (std::string username, std::string password, Coordinates spawnCoordinate)
 Fetches player basic data from the database (table player) by username. Creates a new player with given username to the database if it does not yet exist. More...
 
std::vector< int > loadInventoryDataFromDb (int playerId)
 Load player's inventory items from the database. More...
 
std::vector< int > loadEquipmentDataFromDb (int playerId)
 Load player's equipment items from the database. More...
 
std::vector< std::pair< int, int > > loadSkillDataFromDb (int playerId)
 Load player's skill data from the database. More...
 
bool savePlayerToDb (std::shared_ptr< PlayerCharacter > player)
 Save player's basic data, items and skills to the database. More...
 

Private Member Functions

pqxx::work getTransaction ()
 Get a transaction object. More...
 

Private Attributes

std::unique_ptr< pqxx::connection > pConnectionM
 

Detailed Description

Class for handling database queries.

Constructor & Destructor Documentation

◆ DatabaseManager()

DatabaseManager::DatabaseManager ( )
Here is the call graph for this function:

◆ ~DatabaseManager()

DatabaseManager::~DatabaseManager ( )
default

Member Function Documentation

◆ createConnection()

int DatabaseManager::createConnection ( )

Create connection to the database.

Returns
1 if successful, 0 if not
Here is the caller graph for this function:

◆ getTransaction()

pqxx::work DatabaseManager::getTransaction ( )
private

Get a transaction object.

Returns
pqxx::work

◆ loadEquipmentDataFromDb()

std::vector< int > DatabaseManager::loadEquipmentDataFromDb ( int  playerId)

Load player's equipment items from the database.

Parameters
playerId
Returns
Player's equipment items in a vector
Here is the caller graph for this function:

◆ loadInventoryDataFromDb()

std::vector< int > DatabaseManager::loadInventoryDataFromDb ( int  playerId)

Load player's inventory items from the database.

Parameters
playerId
Returns
Player's inventory items in a vector
Here is the caller graph for this function:

◆ loadPlayerDataFromDb()

PlayerTable DatabaseManager::loadPlayerDataFromDb ( std::string  username,
std::string  password,
Coordinates  spawnCoordinate 
)

Fetches player basic data from the database (table player) by username. Creates a new player with given username to the database if it does not yet exist.

Parameters
username
spawnCoordinateThe coordinate on which player is spawned. Used if the player is not found from the db.
Returns
Player basic data as PlayerTable
Here is the caller graph for this function:

◆ loadSkillDataFromDb()

std::vector< std::pair< int, int > > DatabaseManager::loadSkillDataFromDb ( int  playerId)

Load player's skill data from the database.

Parameters
playerId
Returns
Player's skill data in a vector
Here is the caller graph for this function:

◆ savePlayerToDb()

bool DatabaseManager::savePlayerToDb ( std::shared_ptr< PlayerCharacter player)

Save player's basic data, items and skills to the database.

Parameters
player
Returns
True if succesful, else false
Here is the caller graph for this function:

Member Data Documentation

◆ pConnectionM

std::unique_ptr<pqxx::connection> DatabaseManager::pConnectionM
private

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