blob: ef0df840a069b503b16e4b2a5b39a5b630c779e1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
#ifndef MYGRATE_OUTPUT_PQ_PQBINDINGS
#define MYGRATE_OUTPUT_PQ_PQBINDINGS
#include <dbTypes.h>
#include <helpers.h>
#include <initializer_list>
#include <variant>
#include <vector>
namespace MyGrate::Output::Pq {
struct Bindings {
// NOLINTNEXTLINE(hicpp-explicit-conversions)
explicit Bindings(const std::initializer_list<DbValue> & vs)
{
bufs.reserve(vs.size());
values.reserve(vs.size());
lengths.reserve(vs.size());
for (const auto & v : vs) {
std::visit(*this, v);
}
}
template<Stringable T>
void
operator()(const T & v)
{
bufs.emplace_back(std::to_string(v));
const auto & vw {bufs.back()};
values.emplace_back(vw.data());
lengths.emplace_back(vw.length());
}
template<Viewable T>
void
operator()(const T & v)
{
values.emplace_back(v.data());
lengths.emplace_back(v.size());
}
template<typename T>
void
operator()(const T &)
{
throw std::runtime_error("Not implemented");
}
void
operator()(const std::nullptr_t &)
{
values.emplace_back(nullptr);
lengths.emplace_back(0);
}
std::vector<std::string> bufs;
std::vector<const char *> values;
std::vector<int> lengths;
};
}
#endif
|