Ditto 4.6.0
|
A reference to a collection in a Store
.
More...
#include <Collection.hpp>
Public Member Functions | |
Collection (std::shared_ptr< DittoHandleWrapper > ditto_handle_wrapper, std::string name, private_ctor &&) | |
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, the behavior is determined by the given write_strategy . | |
PendingIDSpecificOperation | find_by_id (DocumentId id) const |
Generates a PendingIDSpecificOperation with the provided document ID that can be used to find the document at a point in time or you can chain a call to observe_local or subscribe if you want to get updates about the document over time. | |
PendingCursorOperation | find_all () const |
Generates a PendingCursorOperation that can be used to find all documents in the collection at a point in time or you can chain a call to observe_local or subscribe if you want to get updates about documents in the collection over time. | |
PendingCursorOperation | find (std::string query) const |
Generates a PendingCursorOperation with the provided query that can be used to find the documents matching the query at a point in time or you can chain a call to observe_local or subscribe if you want to get updates about documents matching the query as they occur. | |
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 matching the query at a point in time or you can chain a call to observe_local or subscribe if you want to get updates about documents matching the query as they occur. | |
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. | |
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. | |
Public Attributes | |
std::string | name |
The name of the collection. | |
A reference to a collection in a Store
.
std::shared_ptr< AttachmentFetcher > ditto::Collection::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.
When you encounter a document that contains an attachment the attachment will not automatically be downloaded along with the document. You trigger an attachment to be downloaded locally to a device by calling this method. It will report changes to the status of the fetch attempt as it tries to download it. Assuming it succeeds in downloading the attachment it will call the event_handler
lambda with a completed event object, which will hold a reference to the attachment.
[in] | token | the AttachmentToken relevant to the attachment that you wish to download and observe. |
[in] | event_handler | a lambda that will be called when there is an update relating to the attachment fetch attempt. |
AttachmentFetcher
object, which must be kept alive for the fetch request to proceed and for you to be notified about the attachment's fetch attempt events. PendingCursorOperation ditto::Collection::find | ( | std::string | query | ) | const |
Generates a PendingCursorOperation
with the provided query that can be used to find the documents matching the query at a point in time or you can chain a call to observe_local or subscribe if you want to get updates about documents matching the query as they occur.
[in] | query | the query to run against the collection. |
PendingCursorOperation
that you can use to chain further query-related function calls. PendingCursorOperation ditto::Collection::find | ( | std::string | query, |
nlohmann::json | query_args ) const |
Generates a PendingCursorOperation
with the provided query that can be used to find the documents matching the query at a point in time or you can chain a call to observe_local or subscribe if you want to get updates about documents matching the query as they occur.
This is the recommended function to use when performing queries on a collection if you have any dynamic data included in the query string. It allows you to provide a query string with placeholders, in the form of $args.my_arg_name
, along with an accompanying dictionary of arguments, in the form of { "my_arg_name": "some value" }
, and the placeholders will be appropriately replaced by the matching provided arguments from the dictionary. This includes handling things like wrapping strings in quotation marks and arrays in square brackets, for example.
query[in] | the query to run against the collection. |
query_args[in] | the arguments to use to replace placeholders in the provided query. |
PendingCursorOperation
that you can use to chain further query-related function calls. PendingCursorOperation ditto::Collection::find_all | ( | ) | const |
Generates a PendingCursorOperation
that can be used to find all documents in the collection at a point in time or you can chain a call to observe_local or subscribe if you want to get updates about documents in the collection over time.
PendingCursorOperation
that you can use to chain further query-related function calls. PendingIDSpecificOperation ditto::Collection::find_by_id | ( | DocumentId | id | ) | const |
Generates a PendingIDSpecificOperation
with the provided document ID that can be used to find the document at a point in time or you can chain a call to observe_local or subscribe if you want to get updates about the document over time.
[in] | id | the ID of the document. |
PendingIDSpecificOperation
that you can chain function calls to either get the document immediately or get updates about it over time. Attachment ditto::Collection::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.
The file residing at the provided path will be copied into the Ditto's store. The Attachment
object that is returned is what you can then use to insert an attachment into a document.
You can provide metadata about the attachment, which will be replicated to other peers alongside the file attachment.
Below is a snippet to show how you can use the new_attachment functionality to insert an attachment into a document.
[in] | path | the path to the file that you want to create an attachment with. |
[in] | metadata | metadata relating to the attachment. |
Attachment
object, which can be used to insert the attachment into a document. DocumentId ditto::Collection::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, the behavior is determined by the given write_strategy
.
[in] | content | the value to insert into the collection. created using the the default DocumentId constructor) is provided then Ditto will automatically assign an ID. |
write_strategy | specifies the desired strategy for inserting a document. The default value is WriteStrategy::merge . |