droplet 1.3.0
A multipurpose Discord bot with the hacker in mind
Loading...
Searching...
No Matches
Database Class Reference

#include <Database.hpp>

Collaboration diagram for Database:

Public Member Functions

 Database ()=delete

Static Public Member Functions

static bool connect (const std::string &db_name, const std::string &user, const std::string &password, const std::string &host, const std::string &port)
 connect to a postgres database
static bool connect (const std::string &connection_string)
 connect to a postgres database
static bool hasConnection () noexcept
 checks if the database has an active connection
static void reconnect () noexcept
 reconnects to the database server if the connection was lost
static void disconnect () noexcept
 disconnect from a postgres database
static NativeDatabase::ConnectiongetConnection () noexcept
 returns the database connection. Reconnects if the Database has no active connection

Detailed Description

This is a Database class to manage the connection to a Database it is a wrapper around a Platform specific Database connection for now this is a Postgres Database using the pqxx Library

Constructor & Destructor Documentation

◆ Database()

Database::Database ( )
delete

Member Function Documentation

◆ connect() [1/2]

bool Database::connect ( const std::string & connection_string)
staticnodiscard

connect to a postgres database

Parameters
connection_stringconnection string used to connect to the database
Returns
returns a bool if the connection was successful

◆ connect() [2/2]

bool Database::connect ( const std::string & db_name,
const std::string & user,
const std::string & password,
const std::string & host,
const std::string & port )
staticnodiscard

connect to a postgres database

Parameters
db_namename of the database
userdatabase user that will be used for the log in
passwordthe password that will be used to log in
hostthe ip or domain of the database server
portthe port the database service is listening on
Returns
returns a bool if the connection was successful

◆ disconnect()

void Database::disconnect ( )
staticnoexcept

disconnect from a postgres database

Parameters
connection_stringconnection string used to connect to the database
Returns
returns a bool if the connection was successful

◆ getConnection()

NativeDatabase::Connection * Database::getConnection ( )
staticnoexcept

returns the database connection. Reconnects if the Database has no active connection

Returns
the active database connection as pqxx::connection pointer

◆ hasConnection()

bool Database::hasConnection ( )
staticnoexcept

checks if the database has an active connection

Returns
returns true if the database is connected, false otherwise

◆ reconnect()

void Database::reconnect ( )
staticnoexcept

reconnects to the database server if the connection was lost

Returns
doesn't return anything

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