0

In the website Introduction to Py2neo 2.0

http://py2neo.org/2.0/intro.html

why do we need Pushing & Pulling ? also graph.cypher.begin() and commit(). as below

tx = graph.cypher.begin()
for name in ["Alice", "Bob", "Carol"]:
    tx.append("CREATE (person:Person {name:{name}}) 
    RETURN person", name=name)
    alice, bob, carol = [result.one for result in tx.commit()]

friends = Path(alice, "KNOWS", bob, "KNOWS", carol)
graph.create(friends)`

I used a small py2neo program as below, and it also works ( at least I can see it on localhost:7474 ) ? please explain the two different methods, thanks


alice = Node("Person", name="Alice")
bob = Node("Person", name="Bob")
alice_knows_bob = Relationship(alice, "KNOWS", bob)
graph.create(alice_knows_bob)

2 Answers2

0

Pushing and pulling are explicitly drawn out into methods to allow full control over network traffic. Earlier versions of the library sent and received changes to and from the server as they were made on the client. This was inefficient as separate HTTP requests were made for each individual property change etc. The current push/pull API is modelled to some extent on git by passing synchronisation control to the application developer.

Nigel Small
  • 4,475
  • 1
  • 17
  • 15
  • Is it necessary to commit if I don't use transactions? When I newly create a database, everything works fine. But once I restart the neo4j community server, the results are wrong, even the number of relationships and nodes are wrong. What can be the issue? – Nitin Apr 06 '16 at 22:35
0

I use push very often. It works like this:

# create node
alice = Node("Person", name="Alice")
graph.create(alice)

alice['name'] = 'Bob' # update node

# if you don't push
n = graph.get( alice.id )
print( n['name' ] ) # we get 'Alice'

db.push( alice )

n = graph.get( alice.id )
print( n['name' ] ) # we get 'Bob'
Tran Cuong
  • 507
  • 5
  • 10