mirror of
https://github.com/neuml/txtai.git
synced 2026-10-11 21:39:55 +00:00
Merge pull request #1361 from kartsan03/rdbms-graph-addattribute
Write RDBMS graph attribute changes to the database
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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])
|
||||
|
||||
Reference in New Issue
Block a user