Database header

This commit is contained in:
Debucquoy Anthony 2021-12-28 15:32:39 +01:00
parent 2b8f34f7af
commit 5269c53dc8
4 changed files with 34 additions and 2 deletions

View File

@ -1,4 +1,26 @@
#include "Database.hpp"
#include "Config.hpp"
Database::Database(){
Config conf("config.txt");
std::ostringstream pgsqlConnectingString;
pgsqlConnectingString
<< " host=" << conf.getValue("db_host")
<< " dbname=" << conf.getValue("db_name")
<< " user=" << conf.getValue("db_user")
<< " password=" << conf.getValue("db_pass");
dbconn = new pqxx::connection(pgsqlConnectingString.str());
}
pqxx::result Database::execute(std::string cmd){
pqxx::work w(*dbconn);
pqxx::result r(w.exec(cmd));
w.commit();
return r;
}
void Database::disconnect(){
dbconn->close();
}

View File

@ -1,4 +1,4 @@
#include <pqxx/pqxx>
#include <pqxx/pqxx>
#ifndef DATABASE_H
#define DATABASE_H
@ -7,9 +7,14 @@ class Database
{
private:
pqxx::connection *dbconn;
public:
Database();
pqxx::result execute(std::string cmd);
void disconnect();
};
#endif /* DATABASE_H */

View File

@ -1,7 +1,7 @@
CC=g++
CFLAGS= -Wall -g
LDLIBS= -lpqxx
LDLIBS= -lpqxx -lpq
SOURCES= $(wildcard *.cpp)
all: main

View File

@ -8,7 +8,12 @@ int main( int carg, char* varg[] ){
Config conf("config.txt");
Database db;
Network net;
net.run();
}