tons of fun
This commit is contained in:
32
app/neo4j_utils.py
Normal file
32
app/neo4j_utils.py
Normal file
@ -0,0 +1,32 @@
|
||||
|
||||
from neo4j import GraphDatabase
|
||||
from flask import current_app
|
||||
|
||||
class Neo4jHandler:
|
||||
def __init__(self, uri, user, password):
|
||||
self.driver = GraphDatabase.driver(uri, auth=(user, password))
|
||||
|
||||
def close(self):
|
||||
self.driver.close()
|
||||
|
||||
def create_plant_node(self, uuid, name):
|
||||
with self.driver.session() as session:
|
||||
session.run(
|
||||
"MERGE (p:Plant {uuid: $uuid}) "
|
||||
"SET p.name = $name",
|
||||
uuid=uuid, name=name
|
||||
)
|
||||
|
||||
def create_lineage(self, child_uuid, parent_uuid):
|
||||
with self.driver.session() as session:
|
||||
session.run(
|
||||
"MATCH (child:Plant {uuid: $child_uuid}), (parent:Plant {uuid: $parent_uuid}) "
|
||||
"MERGE (parent)-[:PARENT_OF]->(child)",
|
||||
child_uuid=child_uuid, parent_uuid=parent_uuid
|
||||
)
|
||||
|
||||
def get_neo4j_handler():
|
||||
uri = current_app.config['NEO4J_URI']
|
||||
user = current_app.config['NEO4J_USER']
|
||||
password = current_app.config['NEO4J_PASSWORD']
|
||||
return Neo4jHandler(uri, user, password)
|
Reference in New Issue
Block a user