userver: userver/storages/mysql/impl/bind_helper.hpp Source File
Loading...
Searching...
No Matches
bind_helper.hpp
1#pragma once
2
3#include <boost/pfr/core.hpp>
4
5#include <userver/storages/mysql/impl/io/insert_binder.hpp>
6#include <userver/storages/mysql/impl/io/params_binder.hpp>
7
8USERVER_NAMESPACE_BEGIN
9
10namespace storages::mysql::impl {
11
12class BindHelper final {
13 public:
14 template <typename... Args>
15 static io::ParamsBinder BindParams(const Args&... args) {
16 return io::ParamsBinder::BindParams(args...);
17 }
18
19 template <typename T>
20 static io::ParamsBinder BindRowAsParams(const T& row) {
21 // TODO : reuse DetectIsSuitableRowType from PG
22 using Row = std::decay_t<T>;
23 static_assert(boost::pfr::tuple_size_v<Row> != 0,
24 "Row to insert has zero columns");
25
26 return std::apply(
27 [](const auto&... args) {
28 return impl::io::ParamsBinder::BindParams(args...);
29 },
30 boost::pfr::structure_tie(row));
31 }
32
33 template <typename Container>
34 static io::InsertBinder<Container> BindContainerAsParams(
35 const Container& rows) {
36 return io::InsertBinder{rows};
37 }
38
39 template <typename MapTo, typename Container>
40 static io::InsertBinder<Container, MapTo> BindContainerAsParamsMapped(
41 const Container& rows) {
42 return io::InsertBinder<Container, MapTo>{rows};
43 }
44};
45
46} // namespace storages::mysql::impl
47
48USERVER_NAMESPACE_END