#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. class ElementSkeleton { class Prop { public: Prop(VertexPropertyFamily::PropertyType::PropertyFamilyKey key, Option> &&prop) : key_v(key), prop(std::move(prop)) { } Prop(EdgePropertyFamily::PropertyType::PropertyFamilyKey key, Option> &&prop) : key_e(key), prop(std::move(prop)) { } union { VertexPropertyFamily::PropertyType::PropertyFamilyKey key_v; EdgePropertyFamily::PropertyType::PropertyFamilyKey key_e; }; Option> prop; }; public: ElementSkeleton(DbAccessor &db) : db(db){}; void add_property(VertexPropertyFamily::PropertyType::PropertyFamilyKey key, std::shared_ptr &&prop) { properties.push_back(Prop(key, make_option(std::move(prop)))); } void add_property(EdgePropertyFamily::PropertyType::PropertyFamilyKey key, std::shared_ptr &&prop) { properties.push_back(Prop(key, make_option(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() { auto va = db.vertex_insert(); for (auto l : labels) { // std::cout << *l << std::endl; va.add_label(*l); } for (auto prop : properties) { assert(prop.prop.is_present()); va.set(prop.key_v, prop.prop.take()); } 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")); } auto ve = db.edge_insert(from_va.get(), to_va.get()); if (type.is_present()) { ve.edge_type(*type.get()); } for (auto prop : properties) { assert(prop.prop.is_present()); ve.set(prop.key_e, prop.prop.take()); } return make_option(); } void clear() { el_id = make_option(); to_va = make_option(); from_va = make_option(); type = make_option(); labels.clear(); properties.clear(); } // Returns import local id. Option element_id() { return el_id; } private: // template // void add_propreties(A &ra) // { // for (auto prop : properties) { // assert(prop.prop.is_present()); // ra.set(prop.key, prop.prop.take()); // } // } DbAccessor &db; Option el_id; Option to_va; Option from_va; Option type; std::vector