Skip to content
Snippets Groups Projects

ENH: Support FIND and COUNT queries

Merged Florian Spreckelsen requested to merge f-query into dev
1 unresolved thread
Files
5
@@ -208,7 +208,7 @@ private:
class MultiResultSet : public ResultSet {
public:
~MultiResultSet() = default;
explicit MultiResultSet(MultiTransactionResponse *response);
explicit MultiResultSet(std::vector<std::unique_ptr<Entity>> result_set);
[[nodiscard]] inline auto Size() const noexcept -> int override {
return this->entities.size();
}
@@ -246,6 +246,17 @@ private:
std::unique_ptr<Entity> entity;
};
// TODO(fspreck) One possibility for count-queries: Transaction gets a
// GetQueryCount function that returns exactly this. In case of a
// single FIND Query this will be equivalent to the Size of the
// ResultSet, but it may be different in case of Query + RetrieveById,
// and in case of COUNT queries which have an empty ResultSet. We have
// to think about how to extend this to transactions with more than
// one query in the future. My suggestion is to treat a transaction
// with more than one query as the union of the query results in which
// case the query count would return the cumulative number of
// results. This would even allow the combination of FIND, FIND
// unique, and COUNT, albeit a little strangely.
/**
* @brief Create a transaction via `CaosDBConnection.createTransaction()`
*/
@@ -357,6 +368,17 @@ public:
return *result_set;
}
/**
* Return the result of a count query
*
* Only meaningful if there was exactly one COUNT query executed in
* this transaction. In all other cases, the return value will be
* -1.
*/
[[nodiscard]] inline auto GetCountResult() const -> int {
return query_count;
}
/**
* Return the number of sub-requests in this transaction.
*
@@ -367,6 +389,23 @@ public:
return this->request->requests_size();
}
/**
* Get a JSON representation of the respone.
*
* For debugging.
*/
inline auto ResponseToString() const -> const std::string {
google::protobuf::util::JsonOptions options;
std::string out;
google::protobuf::util::MessageToJsonString(*this->response, &out, options);
return out;
}
/**
* Get a JSON representation of the request.
*
* For debugging.
*/
inline auto RequestToString() const -> const std::string {
google::protobuf::util::JsonOptions options;
std::string out;
@@ -383,6 +422,7 @@ private:
MultiTransactionRequest *request;
mutable MultiTransactionResponse *response;
std::string error_message;
mutable long query_count;
};
template <class InputIterator>
Loading