Ditto 4.4.3
|
These objects are returned when using Collection::find_by_id functionality. More...
#include <PendingIDSpecificOperation.hpp>
Public Member Functions | |
std::shared_ptr< Document > | exec () const |
Execute the find operation to return the document with the matching ID. | |
std::vector< std::unique_ptr< UpdateResult > > | update (std::function< void(MutableDocument &)> fn) |
Update the document with the matching ID using the provided function. | |
bool | remove () const |
Remove the document with the matching ID. | |
bool | evict () const |
Evict the document with the matching ID. | |
std::shared_ptr< Subscription > | subscribe () const |
Subscribe to changes from other peers that occur in relation to the relevant document. | |
std::shared_ptr< LiveQuery > | observe_local (SingleDocumentLiveQueryEventCallback event_callback) const |
Enables you to listen for changes that occur locally in relation to the relevant document. | |
std::shared_ptr< LiveQuery > | 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. | |
Public Attributes | |
std::string | collection_name |
DocumentId | id |
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.
bool ditto::PendingIDSpecificOperation::evict | ( | ) | const |
Evict the document with the matching ID.
true
if the document was found and evicted. false
if the document wasn't found and therefore wasn't evicted. std::shared_ptr< Document > ditto::PendingIDSpecificOperation::exec | ( | ) | const |
Execute the find operation to return the document with the matching ID.
Document
with the ID provided in the Collection::find_by_id call or nullptr
if the document was not found. 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.
[in] | event_callback | 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_local was called on. |
LiveQuery
object that must be kept in scope for as long as you want to keep receiving updates. 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.
[in] | event_callback | 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_local_with_next_signal was called on. |
LiveQuery
object that must be kept in scope for as long as you want to keep receiving updates. bool ditto::PendingIDSpecificOperation::remove | ( | ) | const |
Remove the document with the matching ID.
true
if the document was found and removed. false
if the document wasn't found and therefore wasn't removed. 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.
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. 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.
fn | a 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 . |
UpdateResult
s that describes the updates that were performed on the document. std::string ditto::PendingIDSpecificOperation::collection_name |
The name of the collection that the operation will be performed within.
DocumentId ditto::PendingIDSpecificOperation::id |
The ID of the document that the operation will apply to.