Ditto 4.7.0
Loading...
Searching...
No Matches
QueryResult.hpp
1#ifndef _DITTO_DQL_QUERY_RESULT_
2#define _DITTO_DQL_QUERY_RESULT_
3
4#include "DocumentId.hpp"
5#include "json.hpp"
6
7#include <memory>
8#include <mutex>
9#include <vector>
10
11#include "any.hpp"
12#include <unordered_map>
13
14/* Forward declaration with typedef */
15typedef struct dittoffi_query_result dittoffi_query_result_t;
16typedef struct dittoffi_query_result_item dittoffi_query_result_item_t;
17
18namespace ditto {
19using ValueMap = std::unordered_map<std::string, any>;
20
21class StoreObserver;
22
29 friend class QueryResult;
30
31private:
32 QueryResultItem(dittoffi_query_result_item_t *raw);
33
34 std::shared_ptr<dittoffi_query_result_item> raw;
35 mutable std::shared_ptr<ValueMap> materialized_value;
36 mutable std::unique_ptr<std::mutex> synchronized;
37
38public:
52 std::shared_ptr<ValueMap> value() const;
53
63 bool is_materialized() const;
64
73 void materialize();
74
81 void dematerialize();
82
89 std::vector<uint8_t> cbor_data() const;
90
97 std::string json_string() const;
98};
99
105private:
106 friend class Store;
107 friend class StoreObserver;
108 QueryResult(dittoffi_query_result_t *raw);
109 std::shared_ptr<dittoffi_query_result_t> raw;
110
111public:
115 size_t item_count() const;
120 QueryResultItem get_item(size_t index) const;
121
125 std::vector<QueryResultItem> items() const;
126
134 std::vector<DocumentId> mutated_document_ids() const;
135};
136
137}; // namespace ditto
138#endif // !_DITTO_DQL_QUERY_RESULT_
Represents the returned results when executing a DQL query, containing a QueryResultItem for each mat...
Definition QueryResult.hpp:104
QueryResultItem get_item(size_t index) const
Returns the matching QueryResultItem.
Definition QueryResult.cpp:22
std::vector< QueryResultItem > items() const
Definition QueryResult.cpp:31
std::vector< DocumentId > mutated_document_ids() const
IDs of documents that were mutated by the DQL query. Empty array if no documents have been mutated.
Definition QueryResult.cpp:42
size_t item_count() const
Definition QueryResult.cpp:18
Represents a single match of a DQL query, similar to a "row" in SQL terms. It is a reference type ser...
Definition QueryResult.hpp:28
void dematerialize()
Releases the materialized value from memory. No-op if item is not materialized.
Definition QueryResult.cpp:85
std::string json_string() const
Returns the content of the item as a JSON string.
Definition QueryResult.cpp:87
std::shared_ptr< ValueMap > value() const
Returns the content as a materialized value map.
Definition QueryResult.cpp:65
std::vector< uint8_t > cbor_data() const
Returns the content of the item as CBOR data.
Definition QueryResult.cpp:94
bool is_materialized() const
Returns true if value is currently held materialized in memory, otherwise returns false.
Definition QueryResult.cpp:71
void materialize()
Loads the CBOR representation of the item's content, decodes it as a dictionary so it can be accessed...
Definition QueryResult.cpp:76
Provides access to Collections and a write transaction API.
Definition Store.hpp:29
Definition StoreObserver.hpp:44