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 {
22public:
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
33private:
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
46public:
47 ReplaceOne(formats::bson::Document selector, formats::bson::Document replacement);
48 ~ReplaceOne();
49
50 ReplaceOne(const ReplaceOne&);
51 ReplaceOne(ReplaceOne&&) noexcept;
52 ReplaceOne& operator=(const ReplaceOne&);
53 ReplaceOne& operator=(ReplaceOne&&) noexcept;
54
55 void SetOption(options::Upsert);
56
57private:
58 friend class storages::mongo::operations::Bulk;
59
60 class Impl;
61 static constexpr std::size_t kSize = compiler::SelectSize() //
62 .For64Bit(48)
63 .For32Bit(24);
64 static constexpr size_t kAlignment = alignof(void*);
65 utils::FastPimpl<Impl, kSize, kAlignment, utils::kStrictMatch> impl_;
66};
67
68/// Updates documents as part of bulk operation
69class Update {
70public:
71 enum class Mode { kSingle, kMulti };
72
73 Update(Mode mode, formats::bson::Document selector, formats::bson::Document update);
74 ~Update();
75
76 Update(const Update&);
77 Update(Update&&) noexcept;
78 Update& operator=(const Update&);
79 Update& operator=(Update&&) noexcept;
80
81 void SetOption(options::Upsert);
82
83private:
84 friend class storages::mongo::operations::Bulk;
85
86 class Impl;
87 static constexpr std::size_t kSize = compiler::SelectSize() //
88 .For64Bit(56)
89 .For32Bit(28);
90 static constexpr size_t kAlignment = alignof(void*);
91 utils::FastPimpl<Impl, kSize, kAlignment, utils::kStrictMatch> impl_;
92};
93
94/// Deletes documents as part of bulk operation
95class Delete {
96public:
97 enum class Mode { kSingle, kMulti };
98
99 Delete(Mode mode, formats::bson::Document selector);
100 ~Delete();
101
102 Delete(const Delete&);
103 Delete(Delete&&) noexcept;
104 Delete& operator=(const Delete&);
105 Delete& operator=(Delete&&) noexcept;
106
107 void SetOption() const {}
108
109private:
110 friend class storages::mongo::operations::Bulk;
111
112 class Impl;
113 static constexpr std::size_t kSize = compiler::SelectSize() //
114 .For64Bit(24)
115 .For32Bit(12);
116 static constexpr size_t kAlignment = alignof(void*);
117 utils::FastPimpl<Impl, kSize, kAlignment, utils::kStrictMatch> impl_;
118};
119
120} // namespace storages::mongo::bulk_ops
121
122USERVER_NAMESPACE_END