Ditto  3.0.4
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 
20 namespace ditto {
21 class DittoHandleWrapper;
22 
26 class Collection {
27 private:
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 
42 public:
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 
78 
89 
100  PendingCursorOperation find(std::string query) const;
101 
123  PendingCursorOperation find(std::string query,
124  nlohmann::json query_args) const;
125 
152  Attachment new_attachment(std::string path,
153  std::map<std::string, std::string> metadata =
154  std::map<std::string, std::string>()) const;
155 
176  std::shared_ptr<AttachmentFetcher>
177  fetch_attachment(std::shared_ptr<AttachmentToken> token,
178  AttachmentFetcherEventHandler event_handler) const;
179 };
180 } // namespace ditto
181 #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: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:40
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:32
std::string name
The name of the collection.
Definition: Collection.hpp:50
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:36
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
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:52
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:21
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:18
An identifier for a Document.
Definition: DocumentId.hpp:21