Ditto 4.13.1
 
Loading...
Searching...
No Matches
Collection.hpp
1#ifndef DITTO_COLLECTION_H
2#define DITTO_COLLECTION_H
3
4#include "Attachment.hpp"
5#include "AttachmentFetchEvent.hpp"
6#include "AttachmentFetcher.hpp"
7#include "AttachmentToken.hpp"
8#include "DocumentId.hpp"
9#include "Helpers.hpp"
10#include "PendingCursorOperation.hpp"
11#include "PendingIDSpecificOperation.hpp"
12#include "WriteStrategy.hpp"
13
14#include "json.hpp"
15
16#include <map>
17#include <memory>
18#include <string>
19
20namespace ditto {
21class DittoHandleWrapper;
22
29class DITTO_DEPRECATED_BECAUSE(
30 "Use DQL (Ditto Query Language) instead. For more information see: "
31 "https://ditto.com/link/legacy-to-dql-guide") Collection {
32 DITTO_DISABLE_DEPRECATED_WARNINGS("The legacy query API is deprecated")
33
34private:
35 friend class DocumentHelpers;
36 friend class ScopedWriteTransaction;
37 friend class Store;
38
39 std::shared_ptr<DittoHandleWrapper> ditto_handle_wrapper;
40
41 struct private_ctor {};
42
43 Collection(std::shared_ptr<DittoHandleWrapper> ditto_handle_wrapper,
44 std::string name);
45
46 DocumentId upsert(nlohmann::json content, WriteStrategy write_strategy,
47 CWriteTransaction *txn) const;
48
49public:
50 // Indirect (because of `private_ctor`) private constructor
51 Collection(std::shared_ptr<DittoHandleWrapper> ditto_handle_wrapper,
52 std::string name, private_ctor &&);
53
57 // NOLINTBEGIN(cppcoreguidelines-non-private-member-variables-in-classes)
58 // NOLINTBEGIN(misc-non-private-member-variables-in-classes)
59 std::string name; // TODO(v5): make this private and provide get_name()?
60 // NOLINTEND(misc-non-private-member-variables-in-classes)
61 // NOLINTEND(cppcoreguidelines-non-private-member-variables-in-classes)
62
75 DocumentId upsert(nlohmann::json content,
76 WriteStrategy write_strategy = WriteStrategy::merge) const;
77
89
100
111 PendingCursorOperation find(std::string query) const;
112
134 PendingCursorOperation find(std::string query,
135 nlohmann::json query_args) const;
136
165 DITTO_DEPRECATED Attachment new_attachment(
166 std::string path, std::map<std::string, std::string> metadata =
167 std::map<std::string, std::string>()) const;
168
191 DITTO_DEPRECATED std::shared_ptr<AttachmentFetcher>
192 fetch_attachment(std::shared_ptr<AttachmentToken> token,
193 AttachmentFetcherEventHandler event_handler) const;
194
195 DITTO_REENABLE_WARNINGS
196};
197} // namespace ditto
198#endif
Represents an attachment and can be used to insert the associated attachment into a document at a spe...
Definition Attachment.hpp:22
PendingCursorOperation find(std::string query) const
Generates a PendingCursorOperation with the provided query that can be used to find the documents mat...
PendingIDSpecificOperation find_by_id(DocumentId id) const
Generates a PendingIDSpecificOperation with the provided document ID that can be used to find the doc...
std::string name
The name of the collection.
Definition Collection.hpp:59
PendingCursorOperation find(std::string query, nlohmann::json query_args) const
Generates a PendingCursorOperation with the provided query that can be used to find the documents mat...
PendingCursorOperation find_all() const
Generates a PendingCursorOperation that can be used to find all documents in the collection at a poin...
std::shared_ptr< AttachmentFetcher > fetch_attachment(std::shared_ptr< AttachmentToken > token, AttachmentFetcherEventHandler event_handler) const
Trigger an attachment to be downloaded locally to the device and observe its progress as it does so.
Attachment new_attachment(std::string path, std::map< std::string, std::string > metadata=std::map< std::string, std::string >()) const
Creates a new attachment, which can then be inserted into a document.
DocumentId upsert(nlohmann::json content, WriteStrategy write_strategy=WriteStrategy::merge) const
Inserts a new document into the collection and returns its ID. If the document already exists,...
These objects are returned when using find-like functionality on Collection objects.
Definition PendingCursorOperation.hpp:49
These objects are returned when using Collection::find_by_id functionality.
Definition PendingIDSpecificOperation.hpp:45
Namespace for the Ditto C++ SDK types and functions.
Definition AbstractDocumentPath.hpp:19
WriteStrategy
Definition WriteStrategy.hpp:17
@ merge
Definition WriteStrategy.hpp:22
A thin wrapper around a function that will get called when there are updates relating to an attempt t...
Definition AttachmentFetcher.hpp:19
An identifier for a Document.
Definition DocumentId.hpp:23