userver
C++ Async Framework
Toggle main menu visibility
Loading...
Searching...
No Matches
bulk.hpp
Go to the documentation of this file.
1
#
pragma
once
2
3
/// @file userver/storages/mongo/bulk.hpp
4
/// @brief Bulk collection operation model
5
6
#
include
<
userver
/
storages
/
mongo
/
bulk_ops
.
hpp
>
7
#
include
<
userver
/
storages
/
mongo
/
options
.
hpp
>
8
#
include
<
userver
/
utils
/
fast_pimpl
.
hpp
>
9
10
USERVER_NAMESPACE_BEGIN
11
12
namespace
storages::mongo::impl::cdriver {
13
class
CDriverCollectionImpl;
14
class
CDriverTransactionCollectionImpl;
15
}
// namespace storages::mongo::impl::cdriver
16
17
namespace
storages::mongo::
operations
{
18
19
/// Efficiently executes a number of operations over a single collection
20
class
Bulk
{
21
public
:
22
enum
class
Mode { kOrdered, kUnordered };
23
24
explicit
Bulk(Mode);
25
~Bulk();
26
27
Bulk(
const
Bulk
&) =
delete
;
28
Bulk(
Bulk
&&)
noexcept
;
29
Bulk
& operator=(
const
Bulk
&) =
delete
;
30
Bulk
& operator=(
Bulk
&&)
noexcept
;
31
32
bool
IsEmpty()
const
;
33
34
void
SetOption(
options
::
WriteConcern
::
Level
);
35
void
SetOption(
const
options
::
WriteConcern
&);
36
void
SetOption(
options
::
SuppressServerExceptions
);
37
38
/// Inserts a single document
39
template
<
typename
... Options>
40
void
InsertOne
(formats::
bson
::
Document
document, Options&&... options);
41
42
/// @brief Replaces a single matching document
43
/// @see options::Upsert
44
template
<
typename
... Options>
45
void
ReplaceOne
(formats::
bson
::
Document
selector, formats::
bson
::
Document
replacement, Options&&... options);
46
47
/// @brief Updates a single matching document
48
/// @see options::Upsert
49
template
<
typename
... Options>
50
void
UpdateOne
(formats::
bson
::
Document
selector, formats::
bson
::
Document
update, Options&&... options);
51
52
/// @brief Updates all matching documents
53
/// @see options::Upsert
54
template
<
typename
... Options>
55
void
UpdateMany
(formats::
bson
::
Document
selector, formats::
bson
::
Document
update, Options&&... options);
56
57
/// Deletes a single matching document
58
template
<
typename
... Options>
59
void
DeleteOne
(formats::
bson
::
Document
selector, Options&&... options);
60
61
/// Deletes all matching documents
62
template
<
typename
... Options>
63
void
DeleteMany
(formats::
bson
::
Document
selector, Options&&... options);
64
65
/// @name Prepared sub-operation inserters
66
/// @{
67
void
Append(
const
bulk_ops
::
InsertOne
&);
68
void
Append(
const
bulk_ops
::
ReplaceOne
&);
69
void
Append(
const
bulk_ops
::
Update
&);
70
void
Append(
const
bulk_ops
::
Delete
&);
71
/// @}
72
73
private
:
74
friend
class
storages::mongo::impl::cdriver::CDriverCollectionImpl;
75
friend
class
storages::mongo::impl::cdriver::CDriverTransactionCollectionImpl;
76
77
class
Impl;
78
static
constexpr
size_t kSize = 56;
79
static
constexpr
size_t kAlignment = 8;
80
// MAC_COMPAT: std::string size differs
81
utils
::FastPimpl<Impl, kSize, kAlignment,
false
> impl_;
82
};
83
84
template
<
typename
... Options>
85
void
Bulk
::
InsertOne
(formats::
bson
::
Document
document, Options&&... options) {
86
bulk_ops
::
InsertOne
insert_subop(std::move(document));
87
(insert_subop.SetOption(std::forward<Options>(options)), ...);
88
Append(insert_subop);
89
}
90
91
template
<
typename
... Options>
92
void
Bulk
::
ReplaceOne
(formats::
bson
::
Document
selector, formats::
bson
::
Document
replacement, Options&&... options) {
93
bulk_ops
::
ReplaceOne
replace_subop(std::move(selector), std::move(replacement));
94
(replace_subop.SetOption(std::forward<Options>(options)), ...);
95
Append(replace_subop);
96
}
97
98
template
<
typename
... Options>
99
void
Bulk
::
UpdateOne
(formats::
bson
::
Document
selector, formats::
bson
::
Document
update, Options&&... options) {
100
bulk_ops
::
Update
update_subop(
bulk_ops
::
Update
::Mode::kSingle, std::move(selector), std::move(update));
101
(update_subop.SetOption(std::forward<Options>(options)), ...);
102
Append(update_subop);
103
}
104
105
template
<
typename
... Options>
106
void
Bulk
::
UpdateMany
(formats::
bson
::
Document
selector, formats::
bson
::
Document
update, Options&&... options) {
107
bulk_ops
::
Update
update_subop(
bulk_ops
::
Update
::Mode::kMulti, std::move(selector), std::move(update));
108
(update_subop.SetOption(std::forward<Options>(options)), ...);
109
Append(update_subop);
110
}
111
112
template
<
typename
... Options>
113
void
Bulk
::
DeleteOne
(formats::
bson
::
Document
selector, Options&&... options) {
114
bulk_ops
::
Delete
delete_subop(
bulk_ops
::
Delete
::Mode::kSingle, std::move(selector));
115
(delete_subop
.
SetOption
(
std::forward<Options>(options)
)
, ...);
116
Append(delete_subop);
117
}
118
119
template
<
typename
... Options>
120
void
Bulk
::
DeleteMany
(formats::
bson
::
Document
selector, Options&&... options) {
121
bulk_ops
::
Delete
delete_subop(
bulk_ops
::
Delete
::Mode::kMulti, std::move(selector));
122
(delete_subop
.
SetOption
(
std::forward<Options>(options)
)
, ...);
123
Append(delete_subop);
124
}
125
126
}
// namespace storages::mongo::operations
127
128
USERVER_NAMESPACE_END
userver
storages
mongo
bulk.hpp
Generated on
for userver by
Doxygen
1.17.0