2015-07-07 08:17:21 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <pqxx/pqxx>
|
|
|
|
|
|
|
|
#include "util.hh"
|
|
|
|
|
|
|
|
|
|
|
|
struct Connection : pqxx::connection
|
|
|
|
{
|
|
|
|
Connection() : pqxx::connection(getFlags()) { };
|
|
|
|
|
2015-07-07 08:29:43 +00:00
|
|
|
std::string getFlags()
|
2015-07-07 08:17:21 +00:00
|
|
|
{
|
2015-07-07 08:29:43 +00:00
|
|
|
using namespace nix;
|
|
|
|
auto s = getEnv("HYDRA_DBI", "dbi:Pg:dbname=hydra;");
|
|
|
|
std::string prefix = "dbi:Pg:";
|
|
|
|
if (std::string(s, 0, prefix.size()) != prefix)
|
2015-07-07 08:17:21 +00:00
|
|
|
throw Error("$HYDRA_DBI does not denote a PostgreSQL database");
|
|
|
|
return concatStringsSep(" ", tokenizeString<Strings>(string(s, prefix.size()), ";"));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct receiver : public pqxx::notification_receiver
|
|
|
|
{
|
|
|
|
bool status = false;
|
|
|
|
receiver(pqxx::connection_base & c, const std::string & channel)
|
|
|
|
: pqxx::notification_receiver(c, channel) { }
|
2015-07-07 08:29:43 +00:00
|
|
|
void operator() (const std::string & payload, int pid) override
|
2015-07-07 08:17:21 +00:00
|
|
|
{
|
|
|
|
status = true;
|
|
|
|
};
|
|
|
|
bool get() {
|
|
|
|
bool b = status;
|
|
|
|
status = false;
|
|
|
|
return b;
|
|
|
|
}
|
|
|
|
};
|