Skip to content

Commit f96d53f

Browse files
committed
Nesting and retention
1 parent dce9cfe commit f96d53f

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

test/test_examples.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,36 @@ def test_result_cursor(self):
118118
session.close()
119119
driver.close()
120120

121+
def test_cursor_nesting(self):
122+
driver = GraphDatabase.driver("bolt://localhost")
123+
session = driver.session()
124+
# tag::retain-result-query[]
125+
cursor = session.run("MATCH (person:Person) WHERE person.dept = {dept} "
126+
"RETURN id(person) AS minion", {"dept": "IT"})
127+
while cursor.next():
128+
session.run("MATCH (person) WHERE id(person) = {id} "
129+
"MATCH (boss:Person) WHERE boss.name = {boss} "
130+
"CREATE (person)-[:REPORTS_TO]->(boss)", {"id": cursor["minion"], "boss": "Bob"})
131+
# end::retain-result-query[]
132+
session.close()
133+
driver.close()
134+
135+
def test_result_retention(self):
136+
driver = GraphDatabase.driver("bolt://localhost")
137+
session = driver.session()
138+
# tag::retain-result-process[]
139+
cursor = session.run("MATCH (person:Person) WHERE person.dept = {dept} "
140+
"RETURN id(person) AS minion", {"dept": "IT"})
141+
minion_records = list(cursor.records())
142+
143+
for record in minion_records:
144+
session.run("MATCH (person) WHERE id(person) = {id} "
145+
"MATCH (boss:Person) WHERE boss.name = {boss} "
146+
"CREATE (person)-[:REPORTS_TO]->(boss)", {"id": record["minion"], "boss": "Bob"})
147+
# end::retain-result-process[]
148+
session.close()
149+
driver.close()
150+
121151
def test_transaction_commit(self):
122152
driver = GraphDatabase.driver("bolt://localhost")
123153
session = driver.session()

0 commit comments

Comments
 (0)