So, I got this to work, but I'm left wondering if I'm doing this in a way
that wasn't intended. I'm using Cypher commands and I'm assuming the point
of py2neo was to be an API that could do these types of things without the
need for Cypher in most cases.
Am I right or wrong here? Any comments on how I'm doing this, better ways
of doing this, and or links to resources that helped others learn would be
greatly appreciated. Until then, I'm going to keep hacking things
together...
Here is the working code:
from py2neo import Graph, Node, Relationship
session = Graph("bolt://localhost")
neo4j = session.begin()
# Check for Node C
existing_node = neo4j.run("MATCH (n) WHERE n.name=\"NODE_C\" RETURN n").data()
if existing_node:
print('Node Exists')
# Create Node D
neo_data_d = Node("NODE", name="NODE_D")
neo4j.create(neo_data_d)
# Create Relationship
rel = neo4j.run("MATCH (n:NODE{name:'NODE_C'}),(p:NODE{name:'NODE_D'})
CREATE (n) -[r:REL]-> (p) RETURN n,p,r").data()
print('Node:', rel)
neo4j.commit()
else:
print('Node Does Not Exist')
# Wipe Database
session.delete_all()
# Create Nodes A,B,C
neo_data_a = Node("NODE", name="NODE_A")
neo4j.create(neo_data_a)
neo_data_b = Node("NODE", name="NODE_B")
neo4j.create(neo_data_b)
neo_data_c = Node("NODE", name="NODE_C")
neo4j.create(neo_data_c)
# Create Relationships A-B-C
rel = Relationship(neo_data_a, "REL", neo_data_b)
neo4j.create(rel)
rel = Relationship(neo_data_b, "REL", neo_data_c)
neo4j.create(rel)
neo4j.commit()
--
You received this message because you are subscribed to the Google Groups
"Neo4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.