lib/redgraph/graph/node_methods.rb in redgraph-0.2.0 vs lib/redgraph/graph/node_methods.rb in redgraph-0.2.1
- old
+ new
@@ -71,10 +71,28 @@
# RedisGraph bug: if there are no matches COUNT returns zero rows
# https://github.com/RedisGraph/RedisGraph/issues/1455
query(cmd).flatten[0] || 0
end
+ def update_node(node)
+ return false unless node.persisted?
+ _set = node.properties.map do |(key, val)|
+ "node.#{key} = #{escape_value(val)}"
+ end.join(", ")
+
+ cmd = "MATCH (node) WHERE ID(node) = #{node.id} SET #{_set} RETURN node"
+ result = _query(cmd)
+ node_from_resultset_item(result.resultset.first["node"])
+ end
+
+ def destroy_node(node)
+ return false unless node.persisted?
+ cmd = "MATCH (node) WHERE ID(node) = #{node.id} DELETE node"
+ result = _query(cmd)
+ result.stats["nodes_deleted"] == 1
+ end
+
private
# Builds a Node object from the raw data
#
def node_from_resultset_item(item)
@@ -96,9 +114,10 @@
# return false if result.stats[:nodes_created] != 1
id = result.resultset.first["ID(node)"]
node.id = id
node
end
+
end
end
end