Ditto 4.5.3
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 CDqlResponse CDqlResponse_t;
16typedef struct CDqlResult CDqlResult_t;
17
18namespace ditto {
19using ValueMap = std::unordered_map<std::string, any>;
20
21class StoreObserver;
22
29 friend class QueryResult;
30
31private:
32 QueryResultItem(CDqlResult_t *raw);
33
34 std::shared_ptr<CDqlResult> 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(CDqlResponse_t *raw);
109 std::shared_ptr<CDqlResponse_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_
Representes the returned results when executing a DQL query, containing a QueryResultItem for each ma...
Definition QueryResult.hpp:104
QueryResultItem get_item(size_t index) const
Returns the matching QueryResultItem.
Definition QueryResult.cpp:20
std::vector< QueryResultItem > items() const
Definition QueryResult.cpp:29
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:40
size_t item_count() const
Definition QueryResult.cpp:16
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:84
std::string json_string() const
Returns the content of the item as a JSON string.
Definition QueryResult.cpp:86
std::shared_ptr< ValueMap > value() const
Returns the content as a materialized value map.
Definition QueryResult.cpp:63
std::vector< uint8_t > cbor_data() const
Returns the content of the item as CBOR data.
Definition QueryResult.cpp:93
bool is_materialized() const
Returns true if value is currently held materialized in memory, otherwise returns false.
Definition QueryResult.cpp:69
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:25
Definition StoreObserver.hpp:45