Skip to content

Commit 41cf203

Browse files
authored
API docs: make simple example self-contained (#751)
When demonstrating how to create nodes/relationships, the queries should entail everything needed so that the example as is, does something useful on en empty database.
1 parent 86df70c commit 41cf203

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

docs/source/index.rst

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ To deactivate the current active virtual environment, use:
9797
Quick Example
9898
*************
9999

100-
Creating nodes.
100+
Creating nodes and relationships.
101101

102102
.. code-block:: python
103103
@@ -106,15 +106,17 @@ Creating nodes.
106106
uri = "neo4j://localhost:7687"
107107
driver = GraphDatabase.driver(uri, auth=("neo4j", "password"))
108108
109+
def create_person(tx, name):
110+
tx.run("CREATE (a:Person {name: $name})", name=name)
111+
109112
def create_friend_of(tx, name, friend):
110113
tx.run("MATCH (a:Person) WHERE a.name = $name "
111114
"CREATE (a)-[:KNOWS]->(:Person {name: $friend})",
112115
name=name, friend=friend)
113116
114117
with driver.session() as session:
118+
session.write_transaction(create_person, "Alice")
115119
session.write_transaction(create_friend_of, "Alice", "Bob")
116-
117-
with driver.session() as session:
118120
session.write_transaction(create_friend_of, "Alice", "Carl")
119121
120122
driver.close()
@@ -132,8 +134,8 @@ Finding nodes.
132134
def get_friends_of(tx, name):
133135
friends = []
134136
result = tx.run("MATCH (a:Person)-[:KNOWS]->(f) "
135-
"WHERE a.name = $name "
136-
"RETURN f.name AS friend", name=name)
137+
"WHERE a.name = $name "
138+
"RETURN f.name AS friend", name=name)
137139
for record in result:
138140
friends.append(record["friend"])
139141
return friends

0 commit comments

Comments
 (0)