Fix repl/single_query
Reviewers: mferencevic, teon.banek Reviewed By: teon.banek Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D1503
This commit is contained in:
parent
2c50ea41d5
commit
98350274ad
@ -24,36 +24,21 @@ class ResultStreamFaker {
|
||||
ResultStreamFaker(ResultStreamFaker &&) = default;
|
||||
ResultStreamFaker &operator=(ResultStreamFaker &&) = default;
|
||||
|
||||
void Header(const std::vector<std::string> &fields) {
|
||||
DCHECK(current_state_ == State::Start)
|
||||
<< "Headers can only be written in the beginning";
|
||||
header_ = fields;
|
||||
current_state_ = State::WritingResults;
|
||||
}
|
||||
void Header(const std::vector<std::string> &fields) { header_ = fields; }
|
||||
|
||||
void Result(const std::vector<TResultValue> &values) {
|
||||
DCHECK(current_state_ == State::WritingResults)
|
||||
<< "Can't accept results before header nor after summary";
|
||||
results_.push_back(values);
|
||||
}
|
||||
|
||||
void Summary(const std::map<std::string, TResultValue> &summary) {
|
||||
DCHECK(current_state_ != State::Done) << "Can only send a summary once";
|
||||
summary_ = summary;
|
||||
current_state_ = State::Done;
|
||||
}
|
||||
|
||||
const auto &GetHeader() const {
|
||||
DCHECK(current_state_ != State::Start) << "Header not written";
|
||||
return header_;
|
||||
}
|
||||
const auto &GetHeader() const { return header_; }
|
||||
|
||||
const auto &GetResults() const { return results_; }
|
||||
|
||||
const auto &GetSummary() const {
|
||||
DCHECK(current_state_ == State::Done) << "Summary not written";
|
||||
return summary_;
|
||||
}
|
||||
const auto &GetSummary() const { return summary_; }
|
||||
|
||||
friend std::ostream &operator<<(std::ostream &os,
|
||||
const ResultStreamFaker &results) {
|
||||
@ -123,15 +108,6 @@ class ResultStreamFaker {
|
||||
}
|
||||
|
||||
private:
|
||||
/**
|
||||
* Possible states of the Mocker. Used for checking if calls to
|
||||
* the Mocker as in acceptable order.
|
||||
*/
|
||||
enum class State { Start, WritingResults, Done };
|
||||
|
||||
// the current state
|
||||
State current_state_ = State::Start;
|
||||
|
||||
// the data that the record stream can accept
|
||||
std::vector<std::string> header_;
|
||||
std::vector<std::vector<TResultValue>> results_;
|
||||
|
@ -64,9 +64,12 @@ void query::Repl(database::GraphDb &db) {
|
||||
// regular cypher queries
|
||||
try {
|
||||
database::GraphDbAccessor dba(db);
|
||||
ResultStreamFaker<query::TypedValue> results;
|
||||
interpeter(command, dba, {}, false).PullAll(results);
|
||||
std::cout << results;
|
||||
ResultStreamFaker<query::TypedValue> stream;
|
||||
auto results = interpeter(command, dba, {}, false);
|
||||
stream.Header(results.header());
|
||||
results.PullAll(stream);
|
||||
stream.Summary(results.summary());
|
||||
std::cout << stream;
|
||||
dba.Commit();
|
||||
} catch (const query::SyntaxException &e) {
|
||||
std::cout << "SYNTAX EXCEPTION: " << e.what() << std::endl;
|
||||
|
@ -13,8 +13,11 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
database::SingleNode db;
|
||||
database::GraphDbAccessor dba(db);
|
||||
ResultStreamFaker<query::TypedValue> results;
|
||||
query::Interpreter{db}(argv[1], dba, {}, false).PullAll(results);
|
||||
std::cout << results;
|
||||
ResultStreamFaker<query::TypedValue> stream;
|
||||
auto results = query::Interpreter{db}(argv[1], dba, {}, false);
|
||||
stream.Header(results.header());
|
||||
results.PullAll(stream);
|
||||
stream.Summary(results.summary());
|
||||
std::cout << stream;
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user