#pragma once #include #include "database/db_accessor.hpp" #include "storage/model/properties/property_family.hpp" #include "storage/vertex_accessor.hpp" // Holder for element data which he can then insert as a vertex or edge into the // database depending on the available data and called add_* method. class ElementSkeleton { public: ElementSkeleton(DbAccessor &db) : db(db){}; void add_property(StoredProperty &&prop) { properties_v.push_back(std::move(prop)); } void add_property(StoredProperty &&prop) { properties_e.push_back(std::move(prop)); } void set_element_id(size_t id) { el_id = make_option(std::move(id)); } void add_label(Label const &label) { labels.push_back(&label); } void set_type(EdgeType const &type) { this->type = make_option(&type); } void set_from(VertexAccessor &&va) { from_va = make_option(std::move(va)); } void set_to(VertexAccessor &&va) { to_va = make_option(std::move(va)); } VertexAccessor add_vertex() { assert(properties_e.empty()); auto va = db.vertex_insert(); for (auto l : labels) { // std::cout << *l << std::endl; va.add_label(*l); } for (auto prop : properties_v) { va.set(std::move(prop)); } return va; } // Return error msg if unsuccessful Option add_edge() { if (!from_va.is_present()) { return make_option(std::string("From field must be seted")); } if (!to_va.is_present()) { return make_option(std::string("To field must be seted")); } if (!type.is_present()) { return make_option(std::string("Type field must be seted")); } assert(properties_v.empty()); auto ve = db.edge_insert(from_va.get(), to_va.get()); ve.edge_type(*type.get()); for (auto prop : properties_e) { ve.set(std::move(prop)); } return make_option(); } void clear() { el_id = make_option(); to_va = make_option(); from_va = make_option(); type = make_option(); labels.clear(); properties_v.clear(); properties_e.clear(); } // Returns import local id. Option element_id() { return el_id; } private: DbAccessor &db; Option el_id; Option to_va; Option from_va; Option type; std::vector