userver
C++ Async Framework
Toggle main menu visibility
Loading...
Searching...
No Matches
options.hpp
Go to the documentation of this file.
1
#pragma once
2
5
6
#include <chrono>
7
#include <cstddef>
8
#include <cstdint>
9
#include <initializer_list>
10
#include <optional>
11
#include <string>
12
#include <string_view>
13
#include <utility>
14
#include <vector>
15
16
#include <
userver/formats/bson/bson_builder.hpp
>
17
#include <
userver/formats/bson/document.hpp
>
18
#include <
userver/formats/bson/value.hpp
>
19
#include <
userver/formats/bson/value_builder.hpp
>
20
#include <
userver/formats/common/type.hpp
>
21
22
USERVER_NAMESPACE_BEGIN
23
25
namespace
storages::mongo::options
{
26
29
class
ReadPreference {
30
public
:
31
enum
Mode
{
33
kPrimary
,
35
kSecondary
,
38
kPrimaryPreferred
,
41
kSecondaryPreferred
,
43
kNearest
,
44
};
45
46
explicit
ReadPreference
(
Mode
mode);
47
ReadPreference
(
Mode
mode, std::vector<formats::bson::Document> tags);
48
49
Mode
GetMode()
const
;
50
std::optional<std::chrono::seconds> GetMaxStaleness()
const
;
51
const
std::vector<formats::bson::Document>& GetTags()
const
;
52
56
ReadPreference&
SetMaxStaleness
(std::optional<std::chrono::seconds> max_staleness);
57
60
ReadPreference&
AddTag
(
formats::bson::Document
tag);
61
62
private
:
63
Mode
mode_;
64
std::optional<std::chrono::seconds> max_staleness_;
65
std::vector<formats::bson::Document> tags_;
66
};
67
70
enum class
ReadConcern
{
72
kLocal
,
74
kMajority
,
76
kLinearizable
,
78
kAvailable
,
79
};
80
83
class
WriteConcern
{
84
public
:
85
enum
Level
{
87
kMajority
,
89
kUnacknowledged
,
90
};
91
93
static
constexpr
std::chrono::seconds
kDefaultMajorityTimeout
{1};
94
96
explicit
WriteConcern
(
Level
level);
97
99
explicit
WriteConcern
(
size_t
nodes_count);
100
102
explicit
WriteConcern
(std::string tag);
103
104
bool
IsMajority()
const
;
105
size_t
NodesCount()
const
;
106
const
std::string& Tag()
const
;
107
std::optional<bool> Journal()
const
;
108
const
std::chrono::milliseconds& Timeout()
const
;
109
111
WriteConcern
&
SetTimeout
(std::chrono::milliseconds timeout);
112
114
WriteConcern
&
SetJournal
(
bool
value);
115
116
private
:
117
size_t
nodes_count_;
118
bool
is_majority_;
119
std::optional<bool> journal_;
120
std::string tag_;
121
std::chrono::milliseconds timeout_;
122
};
123
125
class
Unordered
{};
126
128
class
Upsert
{};
129
131
class
RetryDuplicateKey
{};
132
134
class
ReturnNew
{};
135
137
class
Skip {
138
public
:
139
constexpr
explicit
Skip(
size_t
value)
140
: value_(value)
141
{}
142
143
size_t
Value()
const
{
return
value_; }
144
145
private
:
146
size_t
value_;
147
};
148
151
class
Limit {
152
public
:
153
constexpr
explicit
Limit(
size_t
value)
154
: value_(value)
155
{}
156
157
size_t
Value()
const
{
return
value_; }
158
159
private
:
160
size_t
value_;
161
};
162
166
class
BatchSize {
167
public
:
168
explicit
BatchSize(
size_t
value)
169
: value_(value)
170
{}
171
172
size_t
Value()
const
{
return
value_; }
173
174
private
:
175
size_t
value_;
176
};
177
182
class
Projection
{
183
public
:
185
Projection
() =
default
;
186
188
Projection
(std::initializer_list<std::string_view> fields_to_include);
189
191
Projection
&
Include
(std::string_view field);
192
196
Projection
&
Exclude
(std::string_view field);
197
207
Projection
&
Slice
(std::string_view field, int32_t limit, int32_t skip = 0);
208
214
Projection
&
ElemMatch
(std::string_view field,
const
formats::bson::Document
& pred);
215
218
const
bson_t* GetProjectionBson()
const
;
220
221
private
:
222
formats::bson::impl::BsonBuilder projection_builder_;
223
};
224
226
class
Sort
{
227
public
:
228
enum
Direction {
229
kAscending,
230
kDescending,
231
};
232
234
Sort
() =
default
;
235
237
Sort
(std::initializer_list<std::pair<std::string_view, Direction>>);
238
240
Sort
&
By
(std::string_view field, Direction direction);
241
244
const
bson_t* GetSortBson()
const
;
246
247
private
:
248
formats::bson::impl::BsonBuilder sort_builder_;
249
};
250
253
class
Hint
{
254
public
:
256
explicit
Hint
(std::string index_name);
257
259
explicit
Hint
(
formats::bson::Document
index_spec);
260
263
const
formats::bson::Value
& Value()
const
;
265
266
private
:
267
formats::bson::Value
value_;
268
};
269
273
class
ArrayFilters
{
274
public
:
276
explicit
ArrayFilters
(std::initializer_list<formats::bson::Document>);
277
279
template
<
typename
Iterator>
280
requires
std::is_convertible_v<typename std::iterator_traits<Iterator>::value_type,
formats::bson::Document
>
281
ArrayFilters
(Iterator first, Iterator last) {
282
formats::bson::ValueBuilder
builder{
formats::common::Type::kArray
};
283
for
(
auto
it = first; it != last; ++it) {
284
builder.
PushBack
(*it);
285
}
286
value_ = builder.
ExtractValue
();
287
}
288
291
const
formats::bson::Value
& Value()
const
;
293
294
private
:
295
formats::bson::Value
value_;
296
};
297
299
class
AllowPartialResults
{};
300
305
class
SuppressServerExceptions
{};
306
310
class
Tailable
{};
311
313
class
Comment {
314
public
:
315
explicit
Comment(std::string);
316
317
const
std::string& Value()
const
;
318
319
private
:
320
std::string value_;
321
};
322
325
class
MaxServerTime {
326
public
:
327
constexpr
explicit
MaxServerTime(
const
std::chrono::milliseconds& value)
328
: value_(value)
329
{}
330
331
const
std::chrono::milliseconds& Value()
const
{
return
value_; }
332
333
private
:
334
std::chrono::milliseconds value_;
335
};
336
340
class
Collation
final {
341
public
:
342
enum class
Strength
{
344
kPrimary
= 1,
346
kSecondary
= 2,
348
kTertiary
= 3,
350
kQuaternary
= 4,
352
kIdentical
= 5
353
};
354
355
enum class
CaseFirst
{
357
kOff
,
359
kUpper
,
361
kLower
362
};
363
364
enum class
Alternate
{
366
kNonIgnorable
,
368
kShifted
369
};
370
371
enum class
MaxVariable
{
373
kPunct
,
375
kSpace
376
};
377
379
explicit
Collation
(std::string locale);
380
383
Collation
&
SetStrength
(
Strength
strength);
384
387
Collation
&
SetCaseLevel
(
bool
case_level);
388
391
Collation
&
SetCaseFirst
(
CaseFirst
case_first);
392
395
Collation
&
SetNumericOrdering
(
bool
numeric_ordering);
396
399
Collation
&
SetAlternate
(
Alternate
alternate);
400
403
Collation
&
SetMaxVariable
(
MaxVariable
max_variable);
404
407
Collation
&
SetBackwards
(
bool
backwards);
408
411
Collation
&
SetNormalization
(
bool
normalization);
412
415
const
bson_t* GetCollationBson()
const
;
417
418
private
:
419
formats::bson::impl::BsonBuilder collation_builder_;
420
};
421
422
}
// namespace storages::mongo::options
423
424
USERVER_NAMESPACE_END
userver
storages
mongo
options.hpp
Generated on
for userver by
Doxygen
1.17.0