userver: userver/storages/mysql/impl/io/result_binder.hpp Source File
⚠️ This is the documentation for an old userver version. Click here to switch to the latest version.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
result_binder.hpp
1#pragma once
2
3#include <cstdint>
4#include <optional>
5
6#include <boost/pfr/core.hpp>
7
8#include <userver/storages/mysql/impl/binder_fwd.hpp>
9#include <userver/storages/mysql/impl/io/binder_declarations.hpp>
10#include <userver/storages/mysql/row_types.hpp>
11
12USERVER_NAMESPACE_BEGIN
13
14namespace storages::mysql::impl::io {
15
16class ResultBinder final {
17 public:
18 explicit ResultBinder(std::size_t size);
19 ~ResultBinder();
20
21 ResultBinder(const ResultBinder& other) = delete;
22 ResultBinder(ResultBinder&& other) noexcept;
23
24 template <typename T, typename ExtractionTag>
25 OutputBindingsFwd& BindTo(T& row, ExtractionTag) {
26 if constexpr (std::is_same_v<ExtractionTag, RowTag>) {
27 boost::pfr::for_each_field(
28 row, [&binds = GetBinds()](auto& field, std::size_t i) {
29 storages::mysql::impl::io::BindOutput(binds, i, field);
30 });
31 } else {
32 static_assert(std::is_same_v<ExtractionTag, FieldTag>);
33 storages::mysql::impl::io::BindOutput(GetBinds(), 0, row);
34 }
35
36 return GetBinds();
37 }
38
39 OutputBindingsFwd& GetBinds();
40
41 private:
42 OutputBindingsPimpl impl_;
43};
44
45} // namespace storages::mysql::impl::io
46
47USERVER_NAMESPACE_END