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"
27class DittoHandleWrapper;
64 friend class AttachmentFetcher;
66 friend class StoreObserver;
67 friend class Transaction;
69 static bool finalize_attachment_fetcher(
70 std::shared_ptr<AttachmentFetcher>
const &attachment_fetcher,
71 std::shared_ptr<std::set<std::shared_ptr<AttachmentFetcher>>>
const
73 std::lock_guard<std::mutex>
const &lock);
75 std::shared_ptr<DittoHandleWrapper> ditto_handle_wrapper;
77 Store(std::shared_ptr<DittoHandleWrapper> ditto_handle_wrapper);
78 void set_weak_ditto_fields(std::weak_ptr<Ditto::Fields> weak_ditto_fields);
79 std::weak_ptr<Ditto::Fields> weak_ditto_fields;
82 std::shared_ptr<std::mutex> attachment_fetchers_lock;
83 mutable std::shared_ptr<std::set<std::shared_ptr<AttachmentFetcher>>>
86 bool unregister_observer(std::shared_ptr<StoreObserver>);
88#ifdef DITTO_INTERNAL_TESTING
91 std::vector<TransactionInfo> get_transactions()
const;
129 std::vector<std::unique_ptr<WriteTransactionResult>>
179 std::shared_ptr<StoreObserver>
202 std::shared_ptr<StoreObserver>
204 StoreObservationHandler change_handler);
220 std::shared_ptr<StoreObserver>
222 StoreObservationHandlerWithNextSignal change_handler);
241 std::shared_ptr<StoreObserver>
243 StoreObservationHandlerWithNextSignal change_handler);
281 std::map<std::string, std::string> metadata =
282 std::map<std::string, std::string>())
const;
314 std::shared_ptr<AttachmentFetcher>
348 std::shared_ptr<AttachmentFetcher>
410 const std::function<TransactionCompletionAction(Transaction &)> &fn);
418 const std::function<TransactionCompletionAction(Transaction &)> &fn);
429 const std::function<
void(Transaction &)> &fn);
450 template <
typename T>
452 const std::function<T(Transaction &)> &fn) {
453 std::promise<T> promise;
454 auto future = promise.get_future();
457 &fn](Transaction &
transaction) -> TransactionCompletionAction {
460 return TransactionCompletionAction::commit;
461 }
catch (
const std::exception &e) {
462 promise.set_exception(std::current_exception());
479 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
A reference to a collection in a Store.
Definition Collection.hpp:27
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:58
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.
Definition Store.cpp:113
T transaction_returning(const std::function< T(Transaction &)> &fn)
Convenience method, same as transaction(std::function<TransactionCompletionAction(Transaction &)>,...
Definition Store.hpp:480
TransactionCompletionAction transaction(const TransactionOptions &options, const std::function< TransactionCompletionAction(Transaction &)> &fn)
Executes multiple DQL queries within a single atomic transaction.
Definition Store.cpp:224
DiskUsage get_disk_usage() const
Provides access to the Store's disk usage.
Definition Store.cpp:48
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...
Definition Store.cpp:51
std::set< std::shared_ptr< AttachmentFetcher > > get_attachment_fetchers() const
Returns a copy of all currently active attachment fetchers.
Definition Store.cpp:189
PendingCollectionsOperation collections() const
Returns an object that lets you fetch or observe the collections in the store.
Definition Store.cpp:44
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...
Definition Store.cpp:82
void execute_transaction(const TransactionOptions &options, const std::function< void(Transaction &)> &fn)
Convenience function, same as transaction(TransactionOptions, std::function<TransactionCompletionActi...
Definition Store.cpp:235
std::set< std::shared_ptr< StoreObserver > > observers
Returns a copy of all currently active store observers.
Definition Store.hpp:100
QueryResult execute(std::string query, nlohmann::json query_args=nullptr)
Executes a DQL query and returns matching items as a query result.
Definition Store.cpp:63
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.
Definition Store.cpp:139
Collection collection(std::string name) const
Returns a Collection with the provided name.
Definition Store.cpp:40
T transaction_returning(const TransactionOptions &options, const std::function< T(Transaction &)> &fn)
Convenience method, same as transaction(TransactionOptions, std::function<TransactionCompletionAction...
Definition Store.hpp:451
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:25
A thin wrapper around a function that will get called when there are updates relating to an attempt t...
Definition AttachmentFetcher.hpp:19