Add implementation of C++ API Node::RemoveProperty (#1128)

This commit is contained in:
Matija Pintarić 2023-08-01 20:11:38 +02:00 committed by GitHub
parent 2877c343e8
commit 514fed51c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 0 deletions

View File

@ -637,6 +637,9 @@ class Node {
/// @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;
@ -2574,6 +2577,8 @@ inline void Node::SetProperty(std::string property, Value value) {
mgp::vertex_set_property(ptr_, property.data(), value.ptr());
}
inline void Node::RemoveProperty(std::string property) { SetProperty(property, Value()); }
inline Value Node::GetProperty(const std::string &property) const {
mgp_value *vertex_prop = mgp::vertex_get_property(ptr_, property.data(), memory);
return Value(steal, vertex_prop);

View File

@ -561,6 +561,19 @@ TYPED_TEST(CppApiTestFixture, TestMapErase) {
ASSERT_EQ(map.Size(), 0);
}
TYPED_TEST(CppApiTestFixture, TestNodeRemoveProperty) {
mgp_graph raw_graph = this->CreateGraph(memgraph::storage::View::NEW);
auto graph = mgp::Graph(&raw_graph);
auto node = graph.CreateNode();
int64_t int1 = 100;
mgp::Value value{int1};
node.SetProperty("key", value);
ASSERT_EQ(node.Properties().size(), 1);
node.RemoveProperty("key");
ASSERT_EQ(node.Properties().size(), 0);
}
TYPED_TEST(CppApiTestFixture, TestValuePrint) {
std::string string_1{"abc"};
int64_t int_1{4};