Ditto 4.2.2
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | List of all members
ditto::PendingCursorOperation Class Reference

These objects are returned when using find-like functionality on Collection objects. More...

#include <PendingCursorOperation.hpp>

Public Member Functions

PendingCursorOperationlimit (uint32_t limit)
 Limit the number of documents that get returned when querying a collection for matching documents.
 
PendingCursorOperationoffset (uint32_t offset)
 Offset the resulting set of matching documents.
 
PendingCursorOperationsort (std::string query, SortDirection direction)
 Sort the documents that match the query provided in the preceding find-like function call.
 
std::vector< Documentexec () const
 Execute the query generated by the preceding function chaining and return the list of matching documents.
 
std::unordered_map< DocumentId, std::vector< std::unique_ptr< UpdateResult > >, DocumentIdHasher > update (std::function< void(std::vector< MutableDocument > &)> fn)
 Update documents that match the query generated by the preceding function chaining.
 
std::vector< DocumentIdremove () const
 Remove all documents that match the query generated by the preceding function chaining.
 
std::vector< DocumentIdevict () const
 Evict all documents that match the query generated by the preceding function chaining.
 
std::shared_ptr< Subscriptionsubscribe () const
 Subscribe to changes from other peers that occur in the collection.
 
std::shared_ptr< LiveQueryobserve_local (LiveQueryEventCallback event_callback) const
 Enables you to listen for changes that occur on a collection and match the specified query and qualifiers.
 
std::shared_ptr< LiveQueryobserve_local_with_next_signal (LiveQueryEventWithNextSignalCallback event_callback) const
 Enables you to listen for changes that occur on a collection and match the specified query and qualifiers, and to signal when you are ready for the live query to deliver the next event.
 

Public Attributes

std::string collection_name
 
std::string query
 

Detailed Description

These objects are returned when using find-like functionality on Collection objects.

They allow chaining of further query-related functions to do things like add a limit to the number of documents you want returned or specify how you want the documents to be sorted and ordered.

You can either call exec on the object to get a list of Document objects as 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 a document that matches the query you provided in the preceding find-like call.

A subscription, established by calling subscribe, will act as a signal to other peers that the device connects to that you would like to receive updates from them about documents that match the query you provided in the preceding find-like call.

Member Function Documentation

◆ evict()

std::vector< DocumentId > ditto::PendingCursorOperation::evict ( ) const

Evict all documents that match the query generated by the preceding function chaining.

Returns
a list containing the IDs of the documents that were evicted.

◆ exec()

std::vector< Document > ditto::PendingCursorOperation::exec ( ) const

Execute the query generated by the preceding function chaining and return the list of matching documents.

Returns
a list of Documents matching the query generated by the preceding function chaining.

◆ limit()

PendingCursorOperation & ditto::PendingCursorOperation::limit ( uint32_t  limit)

Limit the number of documents that get returned when querying a collection for matching documents.

Parameters
[in]limitthe maximum number of documents that will be returned.
Returns
a PendingCursorOperation that you can chain further function calls and then either get the matching documents immediately or get updates about them over time.

◆ observe_local()

std::shared_ptr< LiveQuery > ditto::PendingCursorOperation::observe_local ( LiveQueryEventCallback  event_callback) const

Enables you to listen for changes that occur on a collection and match the specified query and qualifiers.

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 with the relevant query. The returned LiveQuery object must be kept in scope for as long as you want the provided handler function to be called when an update occurs.

Parameters
event_callbacka lambda function that will be called every time there is a transaction committed to the store that involves modifications to documents matching the query 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::PendingCursorOperation::observe_local_with_next_signal ( LiveQueryEventWithNextSignalCallback  event_callback) const

Enables you to listen for changes that occur on a collection and match the specified query and qualifiers, 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 with the relevant query. The returned LiveQuery object must be kept in scope for as long as you want the provided handler function to be called when an update occurs.

Parameters
event_callbacka lambda function that will be called every time there is a transaction committed to the store that involves modifications to documents matching the query 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.

◆ offset()

PendingCursorOperation & ditto::PendingCursorOperation::offset ( uint32_t  offset)

Offset the resulting set of matching documents.

This is useful if you aren't interested in the first N matching documents for one reason or another. For example, you might already have queried the collection and obtained the first 20 matching documents and so you might want to run the same query as you did previously but ignore the first 20 matching documents, and that is where you would use offset.

Parameters
[in]offsetthe number of matching documents that you want the eventual resulting set of matching documents to be offset by (and thus not include).
Returns
a PendingCursorOperation that you can chain further function calls and then either get the matching documents immediately or get updates about them over time.

◆ remove()

std::vector< DocumentId > ditto::PendingCursorOperation::remove ( ) const

Remove all documents that match the query generated by the preceding function chaining.

Returns
a list containing the IDs of the documents that were removed.

◆ sort()

PendingCursorOperation & ditto::PendingCursorOperation::sort ( std::string  query,
SortDirection  direction 
)

Sort the documents that match the query provided in the preceding find-like function call.

Parameters
[in]querythe query specifies the logic to be used when sorting the matching documents.
[in]directionspecify whether you want the sorting order to be ascending or descending.
Returns
a PendingCursorOperation that you can chain further function calls and then either get the matching documents immediately or get updates about them over time.

◆ subscribe()

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

Subscribe to changes from other peers that occur in the collection.

Having a subscription acts as a signal to others that you are interested in receiving updates when local or remote changes are made to documents that match the query generated by the chain of operations that precedes the call to subscribe. 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::unordered_map< DocumentId, std::vector< std::unique_ptr< UpdateResult > >, DocumentIdHasher > ditto::PendingCursorOperation::update ( std::function< void(std::vector< MutableDocument > &)>  fn)

Update documents that match the query generated by the preceding function chaining.

Parameters
[in]updatera lambda that gets called with all of the documents matching the query. The documents are MutableDocuments so you can call update-related functions on them.
Returns
a dictionary of document IDs to lists of UpdateResult that describes the updates that were performed for each document.

Member Data Documentation

◆ collection_name

std::string ditto::PendingCursorOperation::collection_name

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

◆ query

std::string ditto::PendingCursorOperation::query

The query that will be used when performing the operation.