The py2neo cursor has attributes relating to if a query is writing data in cursor.summary()
and cursor.stats()
However this dictionary remains the same both before and after graph.commit(tx)
.
How can I confirm that graph.commit(tx)
has written changes to the database?
My code is as follows:
from py2neo import Graph
def process_query(cursor):
# Some logic would go here to create query 2 from the response of query 1.
dummy_query = "CREATE (:Person {name: 'John'})"
return dummy_query
# Create link.
graph = Graph(uri="*****", auth=("*****", "*****"))
# Start transaction.
tx = graph.begin()
# Run first query.
cursor1 = tx.run("MATCH (n) RETURN n")
# Process data from first query.
query2 = process_query(cursor1)
# Run second query.
cursor2 = tx.run(query2)
# Commit the transaction.
graph.commit(tx)
# Need logic here on success of final operation.
I can get the write information from cursor2.stats()
but how should I monitor graph.commit(tx)
if the transaction is unsuccesful? Does it throw an exception or return a specific response?
I have looked at the docs but I cannot get a clear idea on how this function works exactly.