Search code examples
neo4jpy2neo

Neo4J's create, pull, and create_unique


We're using Neo4J and Python (py2neo). Can I get confirmation that graph.create(), graph.pull(), and graph.create_unique() all "commit" their work, in SQL speak? They sure seem to, but this is not the right time to assume.

I've read this page but I am not seeing words like "permanently" with respect to the writes. In a SQL database, an uncommitted transaction looks permanent while one is in the transaction...


Solution

  • You can see exactly what is going on by using py2neo's watch:

    >>> from py2neo import watch, Graph, Node
    >>> watch("httpstream")
    >>> graph = Graph()
    >>> nicole = Node("Person", name="Nicole")
    >>> graph.create(nicole)
    > POST http://localhost:7474/db/data/cypher [80]
    

    So you can see that graph.create is using the legacy Cypher endpoint. If you want to use the transactional endpoint, you'd be better off using transactions:

    >>> tx = graph.cypher.begin()
    >>> tx.append("CREATE (n:Person) SET n = {props}", props={"name":"Nicole"})
    >>> tx.commit()
    > POST http://localhost:7474/db/data/transaction/commit [137]
    

    Which is clearly using the transactional endpoint.