Ditto  1.0.14
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...

Public Member Functions

std::shared_ptr< Documentexec ()
 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 ()
 Remove the document with the matching ID. More...
 
bool evict ()
 Evict the document with the matching ID. More...
 
Subscription subscribe ()
 Subscribe to changes from other peers that occur in relation to the relevant document. More...
 
std::shared_ptr< LiveQueryobserve (SingleDocumentLiveQueryEventHandler event_handler)
 Enables you to listen for changes that occur in relation to the relevant document. More...
 
std::shared_ptr< LiveQueryobserve_local (SingleDocumentLiveQueryEventHandler event_handler)
 Enables you to listen for changes that occur locally in relation to the relevant document. More...
 
std::shared_ptr< LiveQueryobserve_with_next_signal (SingleDocumentLiveQueryWithNextSignalEventHandler event_handler)
 Enables you to listen for changes that occur in relation to the relevant document, and to signal when you are ready for the live query to deliver the next event. More...
 
std::shared_ptr< LiveQueryobserve_local_with_next_signal (SingleDocumentLiveQueryWithNextSignalEventHandler event_handler)
 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, 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.

Calling observe will generate both a subscription and a live query at the same time. If you'd like to only observe local changes then you can call observe_local.

Update and remove functionality is also exposed through this object.

Member Function Documentation

◆ evict()

bool ditto::PendingIDSpecificOperation::evict ( )

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 ( )

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()

std::shared_ptr< LiveQuery > ditto::PendingIDSpecificOperation::observe ( SingleDocumentLiveQueryEventHandler  event_handler)

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

The provided event_handler's function will be called when local or remote changes are made to the document referenced by the Collection::find_by_id call that precedes the call to observe.

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_handleran object containing a 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 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()

std::shared_ptr< LiveQuery > ditto::PendingIDSpecificOperation::observe_local ( SingleDocumentLiveQueryEventHandler  event_handler)

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 use observe or 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_handleran object containing a 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 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 ( SingleDocumentLiveQueryWithNextSignalEventHandler  event_handler)

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 use observe or 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_handleran object containing a 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 was called on.
Returns
a LiveQuery object that must be kept in scope for as long as you want to keep receiving updates.

◆ observe_with_next_signal()

std::shared_ptr< LiveQuery > ditto::PendingIDSpecificOperation::observe_with_next_signal ( SingleDocumentLiveQueryWithNextSignalEventHandler  event_handler)

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

The provided event_handler's function will be called when local or remote changes are made to the document referenced by the Collection::find_by_id call that precedes the call to observe.

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_handleran object containing a 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 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 ( )

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()

Subscription ditto::PendingIDSpecificOperation::subscribe ( )

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.