pgxx/tests/main.cpp

45 lines
812 B
C++
Raw Normal View History

2024-07-18 09:58:33 +03:00
#include <thread>
#include <string>
#include "pgxx/pgxx.hpp"
auto main(int argc, char* args[]) -> int
{
2024-07-18 10:42:44 +03:00
const std::string con = "postgres://chatlanin:password_for_connection_to_test_db@localhost:5423/test.db?sslmode=disable";
2024-07-18 09:58:33 +03:00
try
{
PGXX().init("con_1", 300, con);
PGXX().init("con_2", 300, con);
}
catch(hack::exception& ex)
{
ex.log();
throw;
}
2024-07-18 10:27:17 +03:00
if (!PGXX().ready())
hack::log()("error connection");
2024-07-18 11:41:38 +03:00
pgxx::JSON j {
{
"params", { { "key_1", 1 }, { "key2", "value" } }
}
};
2024-07-24 11:22:39 +03:00
for (auto i = 0; i < 10; ++i)
2024-07-18 11:41:38 +03:00
{
std::thread th([&j](){
auto r = PGXX().execute("con_1", "read_and_write", j);
});
th.detach();
}
2024-07-24 11:22:39 +03:00
for (auto i = 0; i < 10; ++i)
2024-07-18 11:41:38 +03:00
{
auto r = PGXX().execute("con_2", "read_and_write", j);
}
2024-07-18 09:58:33 +03:00
hack::log()("ok");
}