6#include <userver/clients/dns/resolver.hpp>
7#include <userver/engine/deadline.hpp>
8#include <userver/utils/uuid4.hpp>
10#include <userver/storages/mysql.hpp>
12USERVER_NAMESPACE_BEGIN
14namespace storages::
mysql::tests {
16std::uint32_t GetMysqlPort();
18std::chrono::system_clock::time_point ToMariaDBPrecision(std::chrono::system_clock::time_point tp);
20class ClusterWrapper
final {
25 storages::
mysql::Cluster& operator*()
const;
26 storages::
mysql::Cluster* operator->()
const;
28 engine::Deadline GetDeadline()
const;
30 template <
typename... Args>
31 StatementResultSet DefaultExecute(
const std::string& query,
const Args&... args)
const;
34 clients::dns::Resolver resolver_;
35 std::shared_ptr<storages::
mysql::Cluster> cluster_;
37 engine::Deadline deadline_;
40template <
typename... Args>
41StatementResultSet ClusterWrapper::DefaultExecute(
const std::string& query,
const Args&... args)
const {
42 return cluster_->Execute(ClusterHostType::kPrimary, query, args...);
47 explicit TmpTable(std::string_view definition);
48 TmpTable(ClusterWrapper& cluster, std::string_view definition);
51 template <
typename... Args>
52 std::string FormatWithTableName(std::string_view source,
const Args&... args)
const;
54 template <
typename... Args>
55 StatementResultSet DefaultExecute(std::string_view source,
const Args&... args);
57 ClusterWrapper& GetCluster()
const;
61 engine::Deadline GetDeadline()
const;
64 static constexpr std::string_view kCreateTableQueryTemplate =
"CREATE TABLE {} ({})";
66 void CreateTable(std::string_view definition);
68 std::optional<ClusterWrapper> owned_cluster_;
69 ClusterWrapper& cluster_;
70 std::string table_name_;
73template <
typename... Args>
74std::string TmpTable::FormatWithTableName(std::string_view source,
const Args&... args)
const {
75 return fmt::format(fmt::runtime(source), table_name_, args...);
78template <
typename... Args>
79StatementResultSet TmpTable::DefaultExecute(std::string_view source,
const Args&... args) {
80 return cluster_.DefaultExecute(FormatWithTableName(source, table_name_), args...);