userver: userver/ydb/io/primitives.hpp Source File
Loading...
Searching...
No Matches
primitives.hpp
1#pragma once
2
3#include <optional>
4#include <string>
5
6#include <userver/formats/json_fwd.hpp>
7
8#include <userver/ydb/io/traits.hpp>
9#include <userver/ydb/types.hpp>
10
11USERVER_NAMESPACE_BEGIN
12
13namespace ydb {
14
15template <typename PrimitiveTrait>
17 static std::optional<typename PrimitiveTrait::Type> Parse(NYdb::TValueParser& parser, const ParseContext& context);
18
19 static void Write(
20 NYdb::TValueBuilderBase<NYdb::TValueBuilder>& builder,
21 const std::optional<typename PrimitiveTrait::Type>& value
22 );
23
24 static void Write(
25 NYdb::TValueBuilderBase<NYdb::TParamValueBuilder>& builder,
26 const std::optional<typename PrimitiveTrait::Type>& value
27 );
28
29 static NYdb::TType MakeType();
30};
31
32template <typename PrimitiveTrait>
33struct PrimitiveTraits {
34 static typename PrimitiveTrait::Type Parse(NYdb::TValueParser& parser, const ParseContext& context);
35
36 static void
37 Write(NYdb::TValueBuilderBase<NYdb::TValueBuilder>& builder, const typename PrimitiveTrait::Type& value);
38
39 static void
40 Write(NYdb::TValueBuilderBase<NYdb::TParamValueBuilder>& builder, const typename PrimitiveTrait::Type& value);
41
42 static NYdb::TType MakeType();
43};
44
45struct BoolTrait {
46 using Type = bool;
47 static Type Parse(const NYdb::TValueParser& value_parser);
48 template <typename Builder>
49 static void Write(NYdb::TValueBuilderBase<Builder>& builder, Type value);
50};
51
52struct Int32Trait {
53 using Type = std::int32_t;
54 static Type Parse(const NYdb::TValueParser& value_parser);
55 template <typename Builder>
56 static void Write(NYdb::TValueBuilderBase<Builder>& builder, Type value);
57};
58
59struct Uint32Trait {
60 using Type = std::uint32_t;
61 static Type Parse(const NYdb::TValueParser& value_parser);
62 template <typename Builder>
63 static void Write(NYdb::TValueBuilderBase<Builder>& builder, Type value);
64};
65
66struct Int64Trait {
67 using Type = std::int64_t;
68 static Type Parse(const NYdb::TValueParser& value_parser);
69 template <typename Builder>
70 static void Write(NYdb::TValueBuilderBase<Builder>& builder, Type value);
71};
72
73struct Uint64Trait {
74 using Type = std::uint64_t;
75 static Type Parse(const NYdb::TValueParser& value_parser);
76 template <typename Builder>
77 static void Write(NYdb::TValueBuilderBase<Builder>& builder, Type value);
78};
79
80struct DoubleTrait {
81 using Type = double;
82 static Type Parse(const NYdb::TValueParser& value_parser);
83 template <typename Builder>
84 static void Write(NYdb::TValueBuilderBase<Builder>& builder, Type value);
85};
86
87struct StringTrait {
88 using Type = std::string;
89 static Type Parse(const NYdb::TValueParser& value_parser);
90 template <typename Builder>
91 static void Write(NYdb::TValueBuilderBase<Builder>& builder, const Type& value);
92};
93
94struct Utf8Trait {
95 using Type = Utf8;
96 static Type Parse(const NYdb::TValueParser& value_parser);
97 template <typename Builder>
98 static void Write(NYdb::TValueBuilderBase<Builder>& builder, const Type& value);
99};
100
101struct TimestampTrait {
102 using Type = Timestamp;
103 static Type Parse(const NYdb::TValueParser& value_parser);
104 template <typename Builder>
105 static void Write(NYdb::TValueBuilderBase<Builder>& builder, Type value);
106};
107
108struct JsonTrait {
109 using Type = formats::json::Value;
110 static Type Parse(const NYdb::TValueParser& value_parser);
111 template <typename Builder>
112 static void Write(NYdb::TValueBuilderBase<Builder>& builder, const Type& value);
113};
114
115struct JsonDocumentTrait {
116 using Type = JsonDocument;
117 static Type Parse(const NYdb::TValueParser& value_parser);
118 template <typename Builder>
119 static void Write(NYdb::TValueBuilderBase<Builder>& builder, const Type& value);
120};
121
122template <>
123struct ValueTraits<std::optional<JsonDocumentTrait::Type>> : OptionalPrimitiveTraits<JsonDocumentTrait> {};
124
125template <>
126struct ValueTraits<JsonDocument> : PrimitiveTraits<JsonDocumentTrait> {};
127
128template <>
129struct ValueTraits<std::optional<JsonTrait::Type>> : OptionalPrimitiveTraits<JsonTrait> {};
130
131template <>
132struct ValueTraits<formats::json::Value> : PrimitiveTraits<JsonTrait> {};
133
134template <>
135struct ValueTraits<std::optional<TimestampTrait::Type>> : OptionalPrimitiveTraits<TimestampTrait> {};
136
137template <>
138struct ValueTraits<TimestampTrait::Type> : PrimitiveTraits<TimestampTrait> {};
139
140template <>
141struct ValueTraits<std::optional<Utf8Trait::Type>> : OptionalPrimitiveTraits<Utf8Trait> {};
142
143template <>
144struct ValueTraits<Utf8Trait::Type> : PrimitiveTraits<Utf8Trait> {};
145
146template <>
147struct ValueTraits<std::optional<StringTrait::Type>> : OptionalPrimitiveTraits<StringTrait> {};
148
149template <>
150struct ValueTraits<StringTrait::Type> : PrimitiveTraits<StringTrait> {};
151
152template <>
153struct ValueTraits<std::optional<DoubleTrait::Type>> : OptionalPrimitiveTraits<DoubleTrait> {};
154
155template <>
156struct ValueTraits<DoubleTrait::Type> : PrimitiveTraits<DoubleTrait> {};
157
158template <>
159struct ValueTraits<std::optional<Uint64Trait::Type>> : OptionalPrimitiveTraits<Uint64Trait> {};
160
161template <>
162struct ValueTraits<Uint64Trait::Type> : PrimitiveTraits<Uint64Trait> {};
163
164template <>
165struct ValueTraits<std::optional<Int64Trait::Type>> : OptionalPrimitiveTraits<Int64Trait> {};
166
167template <>
168struct ValueTraits<Int64Trait::Type> : PrimitiveTraits<Int64Trait> {};
169
170template <>
171struct ValueTraits<std::optional<Uint32Trait::Type>> : OptionalPrimitiveTraits<Uint32Trait> {};
172
173template <>
174struct ValueTraits<Uint32Trait::Type> : PrimitiveTraits<Uint32Trait> {};
175
176template <>
177struct ValueTraits<std::optional<Int32Trait::Type>> : OptionalPrimitiveTraits<Int32Trait> {};
178
179template <>
180struct ValueTraits<Int32Trait::Type> : PrimitiveTraits<Int32Trait> {};
181
182template <>
183struct ValueTraits<std::optional<BoolTrait::Type>> : OptionalPrimitiveTraits<BoolTrait> {};
184
185template <>
186struct ValueTraits<BoolTrait::Type> : PrimitiveTraits<BoolTrait> {};
187
188} // namespace ydb
189
190USERVER_NAMESPACE_END