Akatas_Kingdom/Database.cpp

27 lines
587 B
C++

#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();
}