Ditto 4.6.0
Loading...
Searching...
No Matches
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 "Helpers.hpp"
15#include "json.hpp"
16
17#include <map>
18#include <memory>
19#include <string>
20
21namespace ditto {
22class DittoHandleWrapper;
23
28private:
29 friend class DocumentHelpers;
30 friend class ScopedWriteTransaction;
31 friend class Store;
32
33 std::shared_ptr<DittoHandleWrapper> ditto_handle_wrapper;
34
35 struct private_ctor {};
36
37 Collection(std::shared_ptr<DittoHandleWrapper> ditto_handle_wrapper,
38 std::string name);
39
40 DocumentId upsert(nlohmann::json content, WriteStrategy write_strategy,
41 CWriteTransaction *txn) const;
42
43public:
44 // Indirect (because of `private_ctor`) private constructor
45 Collection(std::shared_ptr<DittoHandleWrapper> ditto_handle_wrapper,
46 std::string name, private_ctor &&);
47
51 std::string name;
52
66 WriteStrategy write_strategy = WriteStrategy::merge) const;
67
79
90
101 PendingCursorOperation find(std::string query) const;
102
124 PendingCursorOperation find(std::string query,
125 nlohmann::json query_args) const;
126
156 std::string path, std::map<std::string, std::string> metadata =
157 std::map<std::string, std::string>()) const;
158
181 DITTO_DEPRECATED std::shared_ptr<AttachmentFetcher>
182 fetch_attachment(std::shared_ptr<AttachmentToken> token,
184};
185} // namespace ditto
186#endif
Represents an attachment and can be used to insert the associated attachment into a document at a spe...
Definition Attachment.hpp:22
A reference to a collection in a Store.
Definition Collection.hpp:27
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:42
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:34
std::string name
The name of the collection.
Definition Collection.hpp:51
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...
Definition Collection.cpp:38
DITTO_DEPRECATED 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:74
DITTO_DEPRECATED 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:54
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:44
These objects are returned when using Collection::find_by_id functionality.
Definition PendingIDSpecificOperation.hpp:40
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:29
basic_json<> json
default JSON class
Definition json.hpp:2933
Definition Arc.hpp:10
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:21