Ditto 1.1.3
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 uint64_t site_id;
34
35 struct private_ctor {};
36
37 Collection(std::shared_ptr<DittoHandleWrapper> ditto_handle_wrapper,
38 uint64_t site_id, std::string name);
39
40 DocumentId upsert(nlohmann::json content, DocumentId id,
41 WriteStrategy write_strategy, CWriteTransaction *txn) const;
42
43public:
44 // Indirect (because of `private_ctor`) private constructor
45 Collection(std::shared_ptr<DittoHandleWrapper> ditto_handle_wrapper,
46 uint64_t site_id, std::string name, private_ctor &&);
47
51 std::string name;
52
66 WriteStrategy write_strategy = WriteStrategy::merge) const;
67
84 bool is_default = false) const DITTO_DEPRECATED;
85
101 WriteStrategy write_strategy =
102 WriteStrategy::overwrite) const DITTO_DEPRECATED;
103
115
126
138 PendingCursorOperation find(std::string query) const;
139
162 PendingCursorOperation find(std::string query,
163 nlohmann::json query_args) const;
164
191 Attachment new_attachment(std::string path,
192 std::map<std::string, std::string> metadata =
193 std::map<std::string, std::string>()) const;
194
215 std::shared_ptr<AttachmentFetcher>
216 fetch_attachment(std::shared_ptr<AttachmentToken> token,
217 AttachmentFetcherEventHandler event_handler) const;
218};
219} // namespace ditto
220#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:51
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:43
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