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

Provides access to Collections and a write transaction API. More...

#include <Store.hpp>

Public Member Functions

Collection collection (std::string name) const
 Returns a Collection with the provided name.
 
std::vector< std::unique_ptr< WriteTransactionResult > > write (std::function< void(WriteTransaction &)> fn) const
 Allows you to group multiple operations together that affect multiple documents, potentially across multiple collections.
 
PendingCollectionsOperation collections () const
 Returns an object that lets you fetch or observe the collections in the store.
 
DiskUsage get_disk_usage () const
 Provides access to the Store's disk usage.
 
QueryResult execute (std::string query, nlohmann::json query_args=nullptr)
 Executes a DQL query and returns matching items as a query result.
 
std::shared_ptr< StoreObserverregister_observer (std::string query, StoreObservationHandler change_handler)
 Installs and returns a change observer for a query, configuring Ditto to call the provided change handler whenever documents in the local store change such that the result of the matching query changes. The provided query must be a SELECT query.
 
std::shared_ptr< StoreObserverregister_observer (std::string query, nlohmann::json query_args, StoreObservationHandler change_handler)
 Installs and returns a change observer for a query, configuring Ditto to call the provided in change handler whenever documents in the local store change such that the result of the matching query changes. The provided query must be a SELECT query.
 
std::shared_ptr< StoreObserverregister_observer (std::string query, StoreObservationHandlerWithNextSignal change_handler)
 Installs and returns a change observer for a query, configuring Ditto to call the provided change handler whenever documents in the local store change such that the result of the matching query changes. The provided query must be a SELECT query.
 
std::shared_ptr< StoreObserverregister_observer (std::string query, nlohmann::json query_args, StoreObservationHandlerWithNextSignal change_handler)
 Installs and returns a change observer for a query, configuring Ditto to call the provided change handler whenever documents in the local store change such that the result of the matching query changes. The provided query must be a SELECT query.
 

Public Attributes

std::set< std::shared_ptr< StoreObserver > > observers
 

Detailed Description

Provides access to Collections and a write transaction API.

Member Function Documentation

◆ collection()

Collection ditto::Store::collection ( std::string name) const

Returns a Collection with the provided name.

Parameters
[in]namethe name of the collection. A name is valid if:
  • its length is less than 100
  • it does not contain the char '\0'
  • it is not prefixed with "$TS_"
  • it is not empty
Returns
a Collection.
Exceptions
ifname is not a valid Collection name.

◆ collections()

PendingCollectionsOperation ditto::Store::collections ( ) const

Returns an object that lets you fetch or observe the collections in the store.

Returns
a PendingCollectionsOperation object that you can use to fetch or observe the collections in the store

◆ execute()

QueryResult ditto::Store::execute ( std::string query,
nlohmann::json query_args = nullptr )

Executes a DQL query and returns matching items as a query result.

Parameters
querya string containing a valid query expressed in DQL.
query_argsa dictionnary of values keyed by the placeholder name without the leading :.

Limitations:

  • Supports SELECT * FROM <collection_name> with optional WHERE <expression>.
  • No Query parameters as functions arguments yet.
  • No transactions.

◆ get_disk_usage()

DiskUsage ditto::Store::get_disk_usage ( ) const

Provides access to the Store's disk usage.

Returns
a DiskUsage object.

◆ register_observer() [1/4]

std::shared_ptr< StoreObserver > ditto::Store::register_observer ( std::string query,
nlohmann::json query_args,
StoreObservationHandler change_handler )

Installs and returns a change observer for a query, configuring Ditto to call the provided in change handler whenever documents in the local store change such that the result of the matching query changes. The provided query must be a SELECT query.

Parameters
querya string containing a valid query expressed in DQL.
argumentsa dictionary of values keyed by the placeholder name without the leading :. Example: {{"mileage", 123}}.
Returns
An active StoreObserver for the provided query and arguments. You'll have to keep it in scope to keep receiving changes.
  • Throws: DittoError if the query is not a valid DQL query.

◆ register_observer() [2/4]

std::shared_ptr< StoreObserver > ditto::Store::register_observer ( std::string query,
nlohmann::json query_args,
StoreObservationHandlerWithNextSignal change_handler )

Installs and returns a change observer for a query, configuring Ditto to call the provided change handler whenever documents in the local store change such that the result of the matching query changes. The provided query must be a SELECT query.

Parameters
querya string containing a valid query expressed in DQL.
query_argsa dictionary of values keyed by the placeholder name without the leading :. Example: {{"mileage", 123}}.
Returns
: An active StoreObserver for the provided query and arguments. You'll have to keep it in scope to receive changes.

◆ register_observer() [3/4]

std::shared_ptr< StoreObserver > ditto::Store::register_observer ( std::string query,
StoreObservationHandler change_handler )

Installs and returns a change observer for a query, configuring Ditto to call the provided change handler whenever documents in the local store change such that the result of the matching query changes. The provided query must be a SELECT query.

Parameters
querya string containing a valid query expressed in DQL.
Returns
An active StoreObserver for the provided query. You'll have to keep it in scope to receive changes.
  • Throws: DittoError if the query is not a valid DQL query.

◆ register_observer() [4/4]

std::shared_ptr< StoreObserver > ditto::Store::register_observer ( std::string query,
StoreObservationHandlerWithNextSignal change_handler )

Installs and returns a change observer for a query, configuring Ditto to call the provided change handler whenever documents in the local store change such that the result of the matching query changes. The provided query must be a SELECT query.

Parameters
querya string containing a valid query expressed in DQL.
Returns
An active StoreObserver for the provided query. You'll have to keep it in scope to keep receiving changes.

◆ write()

std::vector< std::unique_ptr< WriteTransactionResult > > ditto::Store::write ( std::function< void(WriteTransaction &)> fn) const

Allows you to group multiple operations together that affect multiple documents, potentially across multiple collections.

Parameters
fna lambda that provides access to a write transaction object that can be used to perform operations on the store.
Returns
a list of WriteTransactionResults. There is a result for each operation performed as part of the write transaction.