add new impl for execute

This commit is contained in:
chatlanin 2024-07-18 11:41:38 +03:00
parent 289706408a
commit 062672c68d
2 changed files with 45 additions and 46 deletions

View File

@ -33,29 +33,9 @@ namespace pgxx
}
template<typename... Args>
std::string prepare(const std::string func_name, const Args&... args)
{
std::string query;
try
{
query = builder::make_query(func_name, args...);
}
catch (const std::exception& e)
{
hack::exception ex;
ex.description("database dont create query from args");
ex.system_error(e);
ex.params("query", query);
ex.variadic_params(args...);
throw ex;
}
return query;
}
JSON execute(const std::string connection_name, std::string query)
JSON execute(const std::string connection_name, std::string func_name, const Args&... args)
{
auto query = prepare(func_name, args...);
JSON result;
try
@ -112,6 +92,31 @@ namespace pgxx
return result;
}
private:
template<typename... Args>
std::string prepare(const std::string func_name, const Args&... args)
{
std::string query;
try
{
query = builder::make_query(func_name, args...);
}
catch (const std::exception& e)
{
hack::exception ex;
ex.description("database dont create query from args");
ex.system_error(e);
ex.params("query", query);
ex.variadic_params(args...);
throw ex;
}
return query;
}
};
}

View File

@ -21,30 +21,24 @@ auto main(int argc, char* args[]) -> int
if (!PGXX().ready())
hack::log()("error connection");
// pgxx::JSON j {
// {
// "params", { { "key_1", 1 }, { "key2", "value" } }
// }
// };
//
// for (auto i = 0; i < 1'000; ++i)
// {
// std::thread th([&j](){
// auto query = PGXX().prepare("read_and_write", j);
// auto r = PGXX().execute("con_1", query);
// });
// th.detach();
// }
//
//
// for (auto i = 0; i < 1'000; ++i)
// {
// std::thread th([&j](){
// auto query = PGXX().prepare("read_and_write", j);
// auto r = PGXX().execute("con_2", query);
// });
// th.detach();
// }
pgxx::JSON j {
{
"params", { { "key_1", 1 }, { "key2", "value" } }
}
};
for (auto i = 0; i < 1'000; ++i)
{
std::thread th([&j](){
auto r = PGXX().execute("con_1", "read_and_write", j);
});
th.detach();
}
for (auto i = 0; i < 1'000; ++i)
{
auto r = PGXX().execute("con_2", "read_and_write", j);
}
hack::log()("ok");
}