Ditto 4.13.1
 
Loading...
Searching...
No Matches
PendingCursorOperation.hpp
1#ifndef DITTO_PENDING_CURSOR_OPERATION_H
2#define DITTO_PENDING_CURSOR_OPERATION_H
3
4#include "Document.hpp"
5#include "DocumentId.hpp"
6#include "Helpers.hpp"
7#include "LiveQuery.hpp"
8#include "MutableDocument.hpp"
9#include "SortDirection.hpp"
10#include "Subscription.hpp"
11#include "UpdateResult.hpp"
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
47class DITTO_DEPRECATED_BECAUSE(
48 "Use DQL (Ditto Query Language) instead. For more information see: "
49 "https://ditto.com/link/legacy-to-dql-guide") PendingCursorOperation {
50 DITTO_DISABLE_DEPRECATED_WARNINGS("The legacy query API is deprecated")
51
52 friend class Collection;
53 friend class PendingCollectionsOperation;
54
55 nlohmann::json query_args;
56 uint32_t _offset = 0;
57 int32_t _limit = -1;
58
59 PendingCursorOperation(
60 std::shared_ptr<DittoHandleWrapper> ditto_handle_wrapper,
61 std::string collection_name, std::string query_str,
62 nlohmann::json query_args);
63
64 PendingCursorOperation() = default;
65 PendingCursorOperation(PendingCursorOperation &&other) noexcept;
66 PendingCursorOperation(const PendingCursorOperation &other);
67 PendingCursorOperation &operator=(PendingCursorOperation other);
68
69 class Impl;
70 std::unique_ptr<Impl> impl_;
71
72public:
76 // TODO(v5): make collection_name private and provide a get_collection_name()
77 std::string collection_name; // NOLINT
78
82 // TODO(v5): make query private and provide a get_query() function
83 std::string query; // NOLINT
84
85 ~PendingCursorOperation();
86
87 // Follows the copy-and-swap idiom as described here:
88 // https://stackoverflow.com/a/3279550/2041080
89 friend void swap(PendingCursorOperation &first,
90 PendingCursorOperation &second) noexcept {
91 using std::swap;
92
93 swap(first.collection_name, second.collection_name);
94 swap(first.query, second.query);
95 swap(first.query_args, second.query_args);
96 swap(first._offset, second._offset);
97 swap(first._limit, second._limit);
98 swap(first.impl_, second.impl_);
99 }
100
110 PendingCursorOperation &limit(uint32_t limit);
111
128 PendingCursorOperation &offset(uint32_t offset);
129
144 PendingCursorOperation &sort(std::string query, SortDirection direction);
145
153 std::vector<Document> exec() const;
154
165 std::unordered_map<DocumentId, std::vector<std::unique_ptr<UpdateResult>>,
166 DocumentIdHasher>
167 update(std::function<void(std::vector<MutableDocument> &)> fn);
168
175 std::vector<DocumentId> remove() const;
176
183 std::vector<DocumentId> evict() const;
184
198 std::shared_ptr<Subscription> subscribe() const;
199
218 std::shared_ptr<LiveQuery>
220
240 std::shared_ptr<LiveQuery> observe_local_with_next_signal(
241 LiveQueryEventWithNextSignalCallback event_callback) const;
242
243 DITTO_REENABLE_WARNINGS
244};
245} // namespace ditto
246#endif
std::string query
Definition PendingCursorOperation.hpp:83
std::vector< Document > exec() const
Execute the query generated by the preceding function chaining and return the list of matching docume...
PendingCursorOperation & limit(uint32_t limit)
Limit the number of documents that get returned when querying a collection for matching documents.
std::shared_ptr< LiveQuery > observe_local_with_next_signal(LiveQueryEventWithNextSignalCallback event_callback) const
Enables you to listen for changes that occur on a collection and match the specified query and qualif...
PendingCursorOperation & sort(std::string query, SortDirection direction)
Sort the documents that match the query provided in the preceding find-like function call.
PendingCursorOperation & offset(uint32_t offset)
Offset the resulting set of matching documents.
std::vector< DocumentId > remove() const
Remove all documents that match the query generated by the preceding function chaining.
std::shared_ptr< Subscription > subscribe() const
Subscribe to changes from other peers that occur in the collection.
std::vector< DocumentId > evict() const
Evict all documents that match the query generated by the preceding function chaining.
std::string collection_name
Definition PendingCursorOperation.hpp:77
std::shared_ptr< LiveQuery > observe_local(LiveQueryEventCallback event_callback) const
Enables you to listen for changes that occur on a collection and match the specified query and qualif...
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.
Namespace for the Ditto C++ SDK types and functions.
Definition AbstractDocumentPath.hpp:19
SortDirection
Definition SortDirection.hpp:16
std::function< void(std::vector< Document >, LiveQueryEvent)> LiveQueryEventCallback
A function that will get called when there are updates relating to a live query.
Definition LiveQuery.hpp:88
std::function< void(std::vector< Document >, LiveQueryEvent, std::function< void()> &)> LiveQueryEventWithNextSignalCallback
A function that will get called when there are updates relating to a live query that has an associate...
Definition LiveQuery.hpp:112