4#include "Attachment.hpp"
5#include "AttachmentFetchEvent.hpp"
6#include "AttachmentFetcher.hpp"
7#include "AttachmentToken.hpp"
8#include "Collection.hpp"
9#include "DiskUsage.hpp"
11#include "PendingCollectionsOperation.hpp"
12#include "QueryResult.hpp"
13#include "StoreObserver.hpp"
14#include "Transaction.hpp"
15#include "WriteTransaction.hpp"
16#include "WriteTransactionResult.hpp"
28class DittoHandleWrapper;
66 friend class AttachmentFetcher;
68 friend class StoreObserver;
69 friend class Transaction;
71 static bool finalize_attachment_fetcher(
72 std::shared_ptr<AttachmentFetcher>
const &attachment_fetcher,
73 std::shared_ptr<std::set<std::shared_ptr<AttachmentFetcher>>>
const
75 std::lock_guard<std::mutex>
const &lock);
77 std::shared_ptr<DittoHandleWrapper> ditto_handle_wrapper;
79 explicit Store(std::shared_ptr<DittoHandleWrapper> ditto_handle_wrapper);
80 void set_weak_ditto_fields(std::weak_ptr<Ditto::Fields> weak_ditto_fields);
81 std::weak_ptr<Ditto::Fields> weak_ditto_fields;
84 std::shared_ptr<std::mutex> attachment_fetchers_lock;
85 mutable std::shared_ptr<std::set<std::shared_ptr<AttachmentFetcher>>>
89 std::shared_ptr<std::mutex> observers_lock;
90 bool unregister_observer(std::shared_ptr<StoreObserver>);
92#ifdef DITTO_INTERNAL_TESTING
95 std::vector<TransactionInfo> get_transactions()
const;
100 DITTO_DEPRECATED_BECAUSE(
101 "Use `Ditto::get_store()` to access its `Store` instance.")
109 DITTO_DISABLE_DEPRECATED_WARNINGS(
"`observers` is deprecated")
110 Store(const Store &other) = default;
111 Store(Store &&other) noexcept = default;
112 Store &operator=(const Store &other) = default;
113 Store &operator=(Store &&other) noexcept = default;
115 DITTO_REENABLE_WARNINGS
127 DITTO_DEPRECATED_BECAUSE(
"Use `Store::get_observers()` instead")
146 DITTO_DISABLE_DEPRECATED_WARNINGS(
"`Collection` is deprecated")
161 DITTO_DEPRECATED_BECAUSE(
162 "Use DQL (Ditto Query Language) instead. For more information see: "
163 "https://ditto.com/link/legacy-to-dql-guide")
165 DITTO_REENABLE_WARNINGS
167 DITTO_DISABLE_DEPRECATED_WARNINGS(
"WriteTransaction is deprecated")
180 DITTO_DEPRECATED_BECAUSE(
181 "Use DQL (Ditto Query Language) instead. For more information see: "
182 "https://ditto.com/link/legacy-to-dql-guide")
185 DITTO_REENABLE_WARNINGS
187 DITTO_DISABLE_DEPRECATED_WARNINGS(
"PendingCollectionsOperation is deprecated")
198 DITTO_DEPRECATED_BECAUSE(
199 "Use DQL \"SELECT * from system::collections\" instead.For more "
200 "information see: https://ditto.com/link/legacy-to-dql-guide")
202 DITTO_REENABLE_WARNINGS
242 std::shared_ptr<StoreObserver>
265 std::shared_ptr<StoreObserver>
283 std::shared_ptr<StoreObserver>
304 std::shared_ptr<StoreObserver>
344 std::map<std::
string, std::
string> metadata =
345 std::map<std::
string, std::
string>()) const;
377 std::shared_ptr<AttachmentFetcher>
411 std::shared_ptr<AttachmentFetcher>
492 const std::function<
void(Transaction &)> &fn);
513 template <typename T>
515 const std::function<T(Transaction &)> &fn) {
516 std::promise<T> promise;
517 auto future = promise.get_future();
524 }
catch (
const std::exception &e) {
525 promise.set_exception(std::current_exception());
542 template <
typename T>
Represents an attachment and can be used to insert the associated attachment into a document at a spe...
Definition Attachment.hpp:22
Serves as a token for a specific attachment that you can pass to a call to Store::fetch_attachment.
Definition AttachmentToken.hpp:18
A reference to a collection in a Store.
Definition Collection.hpp:31
Provides an interface to be able to monitor local files.
Definition DiskUsage.hpp:66
These objects are returned when calling collections() on Store objects.
Definition PendingCollectionsOperation.hpp:87
Represents the returned results when executing a DQL query, containing a QueryResultItem for each mat...
Definition QueryResult.hpp:121
Attachment new_attachment(std::string path, std::map< std::string, std::string > metadata=std::map< std::string, std::string >()) const
Creates a new attachment, which can then be inserted into a document.
T transaction_returning(const std::function< T(Transaction &)> &fn)
Convenience method, same as transaction(std::function<TransactionCompletionAction(Transaction &)>,...
Definition Store.hpp:543
TransactionCompletionAction transaction(const TransactionOptions &options, const std::function< TransactionCompletionAction(Transaction &)> &fn)
Executes multiple DQL queries within a single atomic transaction.
DiskUsage get_disk_usage() const
Provides access to the Store's disk usage.
std::set< std::shared_ptr< StoreObserver > > get_observers() const
Return a copy of all currently active store observers.
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 m...
std::set< std::shared_ptr< AttachmentFetcher > > get_attachment_fetchers() const
Returns a copy of all currently active attachment fetchers.
PendingCollectionsOperation collections() const
Returns an object that lets you fetch or observe the collections in the store.
std::shared_ptr< StoreObserver > register_observer(std::string query, StoreObservationHandler change_handler)
Installs and returns a change observer for a query, configuring Ditto to call the provided change han...
void execute_transaction(const TransactionOptions &options, const std::function< void(Transaction &)> &fn)
Convenience function, same as transaction(TransactionOptions, std::function<TransactionCompletionActi...
std::set< std::shared_ptr< StoreObserver > > observers
Returns a copy of all currently active store observers.
Definition Store.hpp:137
QueryResult execute(std::string query, nlohmann::json query_args=nullptr)
Executes a DQL query and returns matching items as a query result.
Store()
Default constructor for Store.
std::shared_ptr< AttachmentFetcher > fetch_attachment(std::shared_ptr< AttachmentToken > token, AttachmentFetcherEventHandler event_handler) const
Trigger an attachment to be downloaded locally to the device and observe its progress as it does so.
Collection collection(std::string name) const
Returns a Collection with the provided name.
T transaction_returning(const TransactionOptions &options, const std::function< T(Transaction &)> &fn)
Convenience method, same as transaction(TransactionOptions, std::function<TransactionCompletionAction...
Definition Store.hpp:514
Options for configuring a transaction.
Definition Transaction.hpp:25
WriteTransaction exposes functionality that allows you to perform multiple operations on the store wi...
Definition WriteTransaction.hpp:30
Polyfill of std::any for C++11.
Definition any.hpp:18
Namespace for the Ditto C++ SDK types and functions.
Definition AbstractDocumentPath.hpp:19
std::function< void(QueryResult)> StoreObservationHandler
A function that will get called when there are updates relating to a store observer.
Definition StoreObserver.hpp:25
std::function< void(QueryResult, NextSignal)> StoreObservationHandlerWithNextSignal
A function that will get called when there are updates relating to a store observer,...
Definition StoreObserver.hpp:33
TransactionCompletionAction
Represents an action that completes a transaction, by either committing it or rolling it back.
Definition Transaction.hpp:80
@ commit
Represents the action of committing a transaction.
Definition Transaction.hpp:82
A thin wrapper around a function that will get called when there are updates relating to an attempt t...
Definition AttachmentFetcher.hpp:19
Provides information about the result of an operation on a document that was part of a write transact...
Definition WriteTransactionResult.hpp:35