Ditto 1.1.3
PendingCursorOperation.hpp
1#ifndef _DITTO_PENDING_CURSOR_OPERATION_
2#define _DITTO_PENDING_CURSOR_OPERATION_
3
4#include "Document.hpp"
5#include "DocumentId.hpp"
6#include "LiveQuery.hpp"
7#include "MutableDocument.hpp"
8#include "SortDirection.hpp"
9#include "Subscription.hpp"
10#include "UpdateResult.hpp"
11
12#include "json.hpp"
13
14#include <functional>
15#include <memory>
16#include <string>
17#include <unordered_map>
18#include <vector>
19
20namespace ditto {
21class DittoHandleWrapper;
22
50 friend class Collection;
51 friend class PendingCollectionsOperation;
52
53 nlohmann::json query_args;
54 uint32_t _offset = 0;
55 int32_t _limit = -1;
56
58 std::shared_ptr<DittoHandleWrapper> ditto_handle_wrapper,
59 std::string collection_name, std::string query_str,
60 nlohmann::json query_args);
61
62 PendingCursorOperation() = default;
66
67 class Impl;
68 std::unique_ptr<Impl> impl_;
69
70public:
74 std::string collection_name;
75
79 std::string query;
80
82
83 // Follows the copy-and-swap idiom as described here:
84 // https://stackoverflow.com/a/3279550/2041080
85 friend void swap(PendingCursorOperation &first,
86 PendingCursorOperation &second) {
87 using std::swap;
88
89 swap(first.collection_name, second.collection_name);
90 swap(first.query, second.query);
91 swap(first.query_args, second.query_args);
92 swap(first._offset, second._offset);
93 swap(first._limit, second._limit);
94 swap(first.impl_, second.impl_);
95 }
96
107
125
138 PendingCursorOperation &sort(std::string query, SortDirection direction);
139
147 std::vector<Document> exec() const;
148
159 std::unordered_map<DocumentId, std::vector<std::unique_ptr<UpdateResult>>,
160 DocumentIdHasher>
161 update(std::function<void(std::vector<MutableDocument> &)> fn);
162
169 std::vector<DocumentId> remove() const;
170
177 std::vector<DocumentId> evict() const;
178
192 Subscription subscribe() const;
193
211 std::shared_ptr<LiveQuery> observe(LiveQueryEventHandler handler) const;
212
231 std::shared_ptr<LiveQuery> observe_local(LiveQueryEventHandler handler) const;
232
251 std::shared_ptr<LiveQuery>
253
273 std::shared_ptr<LiveQuery> observe_local_with_next_signal(
275};
276} // namespace ditto
277#endif
A reference to a collection in a Store.
Definition: Collection.hpp:26
These objects are returned when calling collections() on Store objects.
Definition: PendingCollectionsOperation.hpp:53
These objects are returned when using find-like functionality on Collection objects.
Definition: PendingCursorOperation.hpp:49
std::shared_ptr< LiveQuery > observe_local_with_next_signal(LiveQueryWithNextSignalEventHandler handler) const
Enables you to listen for changes that occur on a collection and match the specified query and qualif...
Definition: PendingCursorOperation.cpp:138
std::shared_ptr< LiveQuery > observe_local(LiveQueryEventHandler handler) const
Enables you to listen for changes that occur on a collection and match the specified query and qualif...
Definition: PendingCursorOperation.cpp:116
std::string query
Definition: PendingCursorOperation.hpp:79
std::vector< Document > exec() const
Execute the query generated by the preceding function chaining and return the list of matching docume...
Definition: PendingCursorOperation.cpp:87
PendingCursorOperation & limit(uint32_t limit)
Limit the number of documents that get returned when querying a collection for matching documents.
Definition: PendingCursorOperation.cpp:151
PendingCursorOperation & sort(std::string query, SortDirection direction)
Sort the documents that match the query provided in the preceding find-like function call.
Definition: PendingCursorOperation.cpp:156
Subscription subscribe() const
Subscribe to changes from other peers that occur in the collection.
Definition: PendingCursorOperation.cpp:203
std::shared_ptr< LiveQuery > observe(LiveQueryEventHandler handler) const
Enables you to listen for changes that occur on a collection and match the specified query and qualif...
Definition: PendingCursorOperation.cpp:102
PendingCursorOperation & offset(uint32_t offset)
Offset the resulting set of matching documents.
Definition: PendingCursorOperation.cpp:146
std::vector< DocumentId > remove() const
Remove all documents that match the query generated by the preceding function chaining.
Definition: PendingCursorOperation.cpp:179
std::vector< DocumentId > evict() const
Evict all documents that match the query generated by the preceding function chaining.
Definition: PendingCursorOperation.cpp:191
std::string collection_name
Definition: PendingCursorOperation.hpp:74
std::shared_ptr< LiveQuery > observe_with_next_signal(LiveQueryWithNextSignalEventHandler handler) const
Enables you to listen for changes that occur on a collection and match the specified query and qualif...
Definition: PendingCursorOperation.cpp:127
std::unordered_map< DocumentId, std::vector< std::unique_ptr< UpdateResult > >, DocumentIdHasher > update(std::function< void(std::vector< MutableDocument > &)> fn)
Update documents that match the query generated by the preceding function chaining.
Definition: PendingCursorOperation.cpp:164
While Subscription objects remain in scope they ensure that documents in the collection specified,...
Definition: Subscription.hpp:17
basic_json<> json
default JSON class
Definition: json.hpp:2933
A thin wrapper around a function that will get called when there are updates relating to a live query...
Definition: LiveQuery.hpp:49
A thin wrapper around a function that will get called when there are updates relating to a live query...
Definition: LiveQuery.hpp:58