Merge pull request #1361 from kartsan03/rdbms-graph-addattribute

Write RDBMS graph attribute changes to the database
This commit is contained in:
David Mezzetti
2026-10-08 13:06:57 -04:00
committed by GitHub
2 changed files with 10 additions and 0 deletions
+4
View File
@@ -59,6 +59,10 @@ class RDBMS(NetworkX):
else:
yield from super().scan(attribute, data)
def addattribute(self, node, field, value):
if self.hasnode(node):
self.graph.backend.add_node(node, {field: value})
def load(self, path):
# Create graph instance
self.graph, self.database = self.connect()
+6
View File
@@ -173,10 +173,16 @@ class TestGraph(unittest.TestCase):
self.assertEqual(list(graph.scan(attribute="field")), [str(x) for x in range(5)])
self.assertEqual(list(graph.filter([0]).scan()), [0])
# Attribute changes must be written through to the database
graph.addattribute(0, "field", "updated")
graph.addattribute(0, "label", "new")
# Test save/load
graph.save(None)
graph.load(None)
self.assertEqual(list(graph.scan()), [str(x) for x in range(5)])
self.assertEqual(graph.node(0), {"field": "updated", "label": "new"})
self.assertEqual(graph.edgecount(), 10)
# Test remove node
graph.delete([0])