-
Notifications
You must be signed in to change notification settings - Fork 0
/
neo4jGraph.py
39 lines (29 loc) · 1.12 KB
/
neo4jGraph.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from neo4j import GraphDatabase
class neo4jDB(object):
def __init__(self, uri, user, password):
self._driver = GraphDatabase.driver(uri, auth=(user, password))
def close(self):
self._driver.close()
def write_greeting(self):
with self._driver.session() as session:
session.run("create (g:Greeting {from:'someone',message:'hello'})")
def read_greeting(self):
with self._driver.session() as session:
greeting = session.run("match (g:Greeting) return g")
print(greeting.single())
def update_greeting(self):
with self._driver.session() as session:
session.run("match (g:Greeting) set g.message = 'hello world'")
def delete_greeting(self):
with self._driver.session() as session:
session.run("match (g:Greeting) where g.message = 'hello world' delete g")
neoDB = neo4jDB('bolt://10.60.47.53:7687', 'liujiafu', 'liujiafu')
print("write")
neoDB.write_greeting()
neoDB.read_greeting()
print("update")
neoDB.update_greeting()
neoDB.read_greeting()
print("delete")
neoDB.delete_greeting()
neoDB.read_greeting()