Ditto 1.1.7
Collection.hpp
1#ifndef _DITTO_COLLECTION_
2#define _DITTO_COLLECTION_
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
27private:
28 friend class DocumentHelpers;
29 friend class ScopedWriteTransaction;
30 friend class Store;
31
32 std::shared_ptr<DittoHandleWrapper> ditto_handle_wrapper;
33
34 struct private_ctor {};
35
36 Collection(std::shared_ptr<DittoHandleWrapper> ditto_handle_wrapper,
37 std::string name);
38
39 DocumentId upsert(nlohmann::json content, DocumentId id,
40 WriteStrategy write_strategy, CWriteTransaction *txn) const;
41
42public:
43 // Indirect (because of `private_ctor`) private constructor
44 Collection(std::shared_ptr<DittoHandleWrapper> ditto_handle_wrapper,
45 std::string name, private_ctor &&);
46
50 std::string name;
51
65 WriteStrategy write_strategy = WriteStrategy::merge) const;
66
83 bool is_default = false) const DITTO_DEPRECATED;
84
100 WriteStrategy write_strategy =
101 WriteStrategy::overwrite) const DITTO_DEPRECATED;
102
114
125
137 PendingCursorOperation find(std::string query) const;
138
161 PendingCursorOperation find(std::string query,
162 nlohmann::json query_args) const;
163
190 Attachment new_attachment(std::string path,
191 std::map<std::string, std::string> metadata =
192 std::map<std::string, std::string>()) const;
193
214 std::shared_ptr<AttachmentFetcher>
215 fetch_attachment(std::shared_ptr<AttachmentToken> token,
216 AttachmentFetcherEventHandler event_handler) const;
217};
218} // namespace ditto
219#endif
These objects are returned by calls to Collection::fetch_attachment.
Definition: AttachmentFetcher.hpp:30
Represents an attachment and can be used to insert the associated attachment into a document at a spe...
Definition: Attachment.hpp:21
Serves as a token for a specific attachment that you can pass to a call to Collection::fetch_attachme...
Definition: AttachmentToken.hpp:16
A reference to a collection in a Store.
Definition: Collection.hpp:26
PendingCursorOperation find(std::string query) const
Generates a PendingCursorOperation with the provided query that can be used to find the documents mat...
Definition: Collection.cpp:54
DocumentId insert(nlohmann::json content, DocumentId id=DocumentId(), bool is_default=false) const DITTO_DEPRECATED
Inserts a new document into the collection and returns the document's ID.
Definition: Collection.cpp:32
PendingIDSpecificOperation find_by_id(DocumentId id) const
Generates a PendingIDSpecificOperation with the provided document ID that can be used to find the doc...
Definition: Collection.cpp:46
std::string name
The name of the collection.
Definition: Collection.hpp:50
PendingCursorOperation find_all() const
Generates a PendingCursorOperation that can be used to find all documents in the collection at a poin...
Definition: Collection.cpp:50
DocumentId insert_with_strategy(nlohmann::json content, DocumentId id=DocumentId(), WriteStrategy write_strategy=WriteStrategy::overwrite) const DITTO_DEPRECATED
Inserts a new document into the collection and returns the document's ID.
Definition: Collection.cpp:41
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.
Definition: Collection.cpp:88
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.
Definition: Collection.cpp:66
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:44
ScopedWriteTransaction exposes functionality that allows you to perform multiple operations on the st...
Definition: ScopedWriteTransaction.hpp:23
Provides access to Collections and a write transaction API.
Definition: Store.hpp:20
namespace for Niels Lohmann
Definition: json.hpp:82
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 an attempt t...
Definition: AttachmentFetcher.hpp:17
An identifier for a Document.
Definition: DocumentId.hpp:21