userver: userver/storages/mongo/bulk_ops.hpp Source File
Loading...
Searching...
No Matches
bulk_ops.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/storages/mongo/bulk_ops.hpp
4/// @brief Bulk sub-operation models
5
6#include <userver/compiler/select.hpp>
7#include <userver/formats/bson/document.hpp>
8#include <userver/storages/mongo/options.hpp>
9#include <userver/utils/fast_pimpl.hpp>
10
11USERVER_NAMESPACE_BEGIN
12
13namespace storages::mongo::operations {
14class Bulk;
15} // namespace storages::mongo::operations
16
17/// Bulk sub-operations
18namespace storages::mongo::bulk_ops {
19
20/// Inserts a single document as part of bulk operation
21class InsertOne {
22 public:
23 explicit InsertOne(formats::bson::Document document);
24 ~InsertOne();
25
26 InsertOne(const InsertOne&);
27 InsertOne(InsertOne&&) noexcept;
28 InsertOne& operator=(const InsertOne&);
29 InsertOne& operator=(InsertOne&&) noexcept;
30
31 void SetOption() const {}
32
33 private:
34 friend class storages::mongo::operations::Bulk;
35
36 class Impl;
37 static constexpr std::size_t kSize = compiler::SelectSize() //
38 .For64Bit(16)
39 .For32Bit(8);
40 static constexpr size_t kAlignment = alignof(void*);
41 utils::FastPimpl<Impl, kSize, kAlignment, utils::kStrictMatch> impl_;
42};
43
44/// Replaces a single document as part of bulk operation
46 public:
47 ReplaceOne(formats::bson::Document selector,
48 formats::bson::Document replacement);
49 ~ReplaceOne();
50
51 ReplaceOne(const ReplaceOne&);
52 ReplaceOne(ReplaceOne&&) noexcept;
53 ReplaceOne& operator=(const ReplaceOne&);
54 ReplaceOne& operator=(ReplaceOne&&) noexcept;
55
56 void SetOption(options::Upsert);
57
58 private:
59 friend class storages::mongo::operations::Bulk;
60
61 class Impl;
62 static constexpr std::size_t kSize = compiler::SelectSize() //
63 .For64Bit(48)
64 .For32Bit(24);
65 static constexpr size_t kAlignment = alignof(void*);
66 utils::FastPimpl<Impl, kSize, kAlignment, utils::kStrictMatch> impl_;
67};
68
69/// Updates documents as part of bulk operation
70class Update {
71 public:
72 enum class Mode { kSingle, kMulti };
73
74 Update(Mode mode, formats::bson::Document selector,
75 formats::bson::Document update);
76 ~Update();
77
78 Update(const Update&);
79 Update(Update&&) noexcept;
80 Update& operator=(const Update&);
81 Update& operator=(Update&&) noexcept;
82
83 void SetOption(options::Upsert);
84
85 private:
86 friend class storages::mongo::operations::Bulk;
87
88 class Impl;
89 static constexpr std::size_t kSize = compiler::SelectSize() //
90 .For64Bit(56)
91 .For32Bit(28);
92 static constexpr size_t kAlignment = alignof(void*);
93 utils::FastPimpl<Impl, kSize, kAlignment, utils::kStrictMatch> impl_;
94};
95
96/// Deletes documents as part of bulk operation
97class Delete {
98 public:
99 enum class Mode { kSingle, kMulti };
100
101 Delete(Mode mode, formats::bson::Document selector);
102 ~Delete();
103
104 Delete(const Delete&);
105 Delete(Delete&&) noexcept;
106 Delete& operator=(const Delete&);
107 Delete& operator=(Delete&&) noexcept;
108
109 void SetOption() const {}
110
111 private:
112 friend class storages::mongo::operations::Bulk;
113
114 class Impl;
115 static constexpr std::size_t kSize = compiler::SelectSize() //
116 .For64Bit(24)
117 .For32Bit(12);
118 static constexpr size_t kAlignment = alignof(void*);
119 utils::FastPimpl<Impl, kSize, kAlignment, utils::kStrictMatch> impl_;
120};
121
122} // namespace storages::mongo::bulk_ops
123
124USERVER_NAMESPACE_END