From a426ef9cc3bc7700a0c78fd3ea87f56f14daf03b Mon Sep 17 00:00:00 2001 From: imilinovic <44698587+imilinovic@users.noreply.github.com> Date: Thu, 24 Aug 2023 12:14:00 +0200 Subject: [PATCH] Add Relationship::RemoveProperty to C++ query module API (#1156) --- include/mgp.hpp | 5 +++++ tests/unit/cpp_api.cpp | 16 ++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/include/mgp.hpp b/include/mgp.hpp index 4329fb79c..9085f6350 100644 --- a/include/mgp.hpp +++ b/include/mgp.hpp @@ -780,6 +780,9 @@ class Relationship { /// @brief Sets the chosen property to the given value. void SetProperty(std::string property, Value value); + /// @brief Removes the chosen property. + void RemoveProperty(std::string property); + /// @brief Retrieves the value of the chosen property. Value GetProperty(const std::string &property) const; @@ -2726,6 +2729,8 @@ inline void Relationship::SetProperty(std::string property, Value value) { mgp::edge_set_property(ptr_, property.data(), value.ptr()); } +inline void Relationship::RemoveProperty(std::string property) { SetProperty(property, Value()); } + inline Value Relationship::GetProperty(const std::string &property) const { mgp_value *edge_prop = mgp::MemHandlerCallback(edge_get_property, ptr_, property.data()); return Value(steal, edge_prop); diff --git a/tests/unit/cpp_api.cpp b/tests/unit/cpp_api.cpp index d2c65b349..70e62110e 100644 --- a/tests/unit/cpp_api.cpp +++ b/tests/unit/cpp_api.cpp @@ -575,6 +575,22 @@ TYPED_TEST(CppApiTestFixture, TestNodeRemoveProperty) { ASSERT_EQ(node.Properties().size(), 0); } +TYPED_TEST(CppApiTestFixture, TestRelationshipRemoveProperty) { + mgp_graph raw_graph = this->CreateGraph(memgraph::storage::View::NEW); + auto graph = mgp::Graph(&raw_graph); + auto node_1 = graph.CreateNode(); + auto node_2 = graph.CreateNode(); + auto relationship = graph.CreateRelationship(node_1, node_2, "Relationship"); + + int64_t int_1{0}; + mgp::Value value{int_1}; + relationship.SetProperty("property", value); + + ASSERT_EQ(relationship.Properties().size(), 1); + relationship.RemoveProperty("property"); + ASSERT_EQ(relationship.Properties().size(), 0); +} + TYPED_TEST(CppApiTestFixture, TestValuePrint) { std::string string_1{"abc"}; int64_t int_1{4};