memgraph/src/query_engine/traverser/read_traverser.hpp

49 lines
1.2 KiB
C++
Raw Normal View History

2016-02-26 06:49:35 +08:00
#pragma once
2016-02-26 14:45:43 +08:00
#include "code.hpp"
2016-02-26 06:49:35 +08:00
#include "cypher/visitor/traverser.hpp"
2016-03-12 17:57:09 +08:00
#include "query_engine/util.hpp"
2016-02-26 06:49:35 +08:00
2016-02-26 14:45:43 +08:00
class ReadTraverser : public Traverser, public Code
2016-02-26 06:49:35 +08:00
{
2016-03-12 17:57:09 +08:00
private:
uint32_t index{0};
public:
std::string code;
void visit(ast::Match& match) override
{
code += line("auto& t = db.tx_engine.begin();");
Traverser::visit(match);
};
void visit(ast::Property& property) override
{
code += line("auto id = args[" + std::to_string(index) + "]->as<Int32>();");
code += line("auto vertex_accessor = db.graph.vertices.find(t, id.value);");
++index;
}
void visit(ast::InternalIdExpr& internal_id) override
{
}
2016-03-12 17:57:09 +08:00
void visit(ast::Return& ret) override
{
#ifdef DEBUG
// TODO: remove from here
code += line("PRINT_PROPS(vertex_accessor.properties());");
code += line("cout << \"LABELS:\" << endl;");
code += line("for (auto label_ref : vertex_accessor.labels()) {");
code += line("cout << label_ref.get() << endl;");
code += line("}");
#endif
2016-03-12 17:57:09 +08:00
code += line("t.commit();");
code += line("return std::make_shared<QueryResult>();");
2016-03-12 17:57:09 +08:00
}
2016-02-26 06:49:35 +08:00
};