Ditto 3.0.3-alpha2
Public Member Functions | Public Attributes | List of all members
ditto::PendingIDSpecificOperation Class Reference

These objects are returned when using Collection::find_by_id functionality. More...

#include <PendingIDSpecificOperation.hpp>

Public Member Functions

std::shared_ptr< Documentexec () const
 Execute the find operation to return the document with the matching ID. More...
 
std::vector< std::unique_ptr< UpdateResult > > update (std::function< void(MutableDocument &)> fn)
 Update the document with the matching ID using the provided function. More...
 
bool remove () const
 Remove the document with the matching ID. More...
 
bool evict () const
 Evict the document with the matching ID. More...
 
std::shared_ptr< Subscriptionsubscribe () const
 Subscribe to changes from other peers that occur in relation to the relevant document. More...
 
std::shared_ptr< LiveQueryobserve_local (SingleDocumentLiveQueryEventCallback event_callback) const
 Enables you to listen for changes that occur locally in relation to the relevant document. More...
 
std::shared_ptr< LiveQueryobserve_local_with_next_signal (SingleDocumentLiveQueryEventWithNextSignalCallback event_callback) const
 Enables you to listen for changes that occur locally in relation to the relevant document, and to signal when you are ready for the live query to deliver the next event. More...
 

Public Attributes

std::string collection_name
 
DocumentId id
 

Detailed Description

These objects are returned when using Collection::find_by_id functionality.

You can either call exec on the object to get an immediate return value, or you can establish either a live query or a subscription, which both work over time.

A live query, established by calling observe_local, will notify you every time there's an update to the document with the ID you provided in the preceding Collection::find_by_id call.

A subscription, established by calling subscribe, will act as a signal to other peers that you would like to receive updates from them about the document with the ID you provided in the preceding Collection::find_by_id call.

Update and remove functionality is also exposed through this object.

Member Function Documentation

◆ evict()

bool ditto::PendingIDSpecificOperation::evict ( ) const

Evict the document with the matching ID.

Returns
true if the document was found and evicted. false if the document wasn't found and therefore wasn't evicted.

◆ exec()

std::shared_ptr< Document > ditto::PendingIDSpecificOperation::exec ( ) const

Execute the find operation to return the document with the matching ID.

Returns
the Document with the ID provided in the Collection::find_by_id call or nullptr if the document was not found.

◆ observe_local()

std::shared_ptr< LiveQuery > ditto::PendingIDSpecificOperation::observe_local ( SingleDocumentLiveQueryEventCallback  event_callback) const

Enables you to listen for changes that occur locally in relation to the relevant document.

This won't subscribe to receive changes made remotely by others and so it will only fire updates when a local change is made. If you want to receive remotely performed updates as well then also call subscribe separately after another Collection::find_by_id call that references the same document ID.

The returned LiveQuery object must be kept in scope for as long as you want the provided event_handler's function to be called when an update occurs.

Parameters
[in]event_callbacka function that will be called every time there is a transaction committed to the store that involves a modification to the document with the relevant ID in the collection that observe_local was called on.
Returns
a LiveQuery object that must be kept in scope for as long as you want to keep receiving updates.

◆ observe_local_with_next_signal()

std::shared_ptr< LiveQuery > ditto::PendingIDSpecificOperation::observe_local_with_next_signal ( SingleDocumentLiveQueryEventWithNextSignalCallback  event_callback) const

Enables you to listen for changes that occur locally in relation to the relevant document, and to signal when you are ready for the live query to deliver the next event.

This won't subscribe to receive changes made remotely by others and so it will only fire updates when a local change is made. If you want to receive remotely performed updates as well then also call subscribe separately after another Collection::find_by_id call that references the same document ID.

The returned LiveQuery object must be kept in scope for as long as you want the provided event_handler's function to be called when an update occurs.

Parameters
[in]event_callbacka function that will be called every time there is a transaction committed to the store that involves a modification to the document with the relevant ID in the collection that observe_local_with_next_signal was called on.
Returns
a LiveQuery object that must be kept in scope for as long as you want to keep receiving updates.

◆ remove()

bool ditto::PendingIDSpecificOperation::remove ( ) const

Remove the document with the matching ID.

Returns
true if the document was found and removed. false if the document wasn't found and therefore wasn't removed.

◆ subscribe()

std::shared_ptr< Subscription > ditto::PendingIDSpecificOperation::subscribe ( ) const

Subscribe to changes from other peers that occur in relation to the relevant document.

Having a subscription acts as a signal to other peers that you are interested in receiving updates when local or remote changes are made to the relevant document. The returned Subscription object must be kept in scope for as long as you want to keep receiving updates.

Returns
A Subscription object that must be kept in scope for as long as you want to keep receiving updates for documents that match the query specified in the preceding chain.

◆ update()

std::vector< std::unique_ptr< UpdateResult > > ditto::PendingIDSpecificOperation::update ( std::function< void(MutableDocument &)>  fn)

Update the document with the matching ID using the provided function.

Parameters
fna lambda that gets called with the document matching the ID. If found, the document is a MutableDocument, so you can call update-related functions on it. If the document is not found then the value provided to the closure will be nullptr.
Returns
a list of UpdateResults that describes the updates that were performed on the document.

Member Data Documentation

◆ collection_name

std::string ditto::PendingIDSpecificOperation::collection_name

The name of the collection that the operation will be performed within.

◆ id

DocumentId ditto::PendingIDSpecificOperation::id

The ID of the document that the operation will apply to.