Skip to content

Commit

Permalink
feat: a file for connecting to the Neo4j DB was added
Browse files Browse the repository at this point in the history
  • Loading branch information
scientiststwin committed Jul 26, 2023
1 parent 8bb1eb8 commit d8c88cc
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions neo4j_connection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import os
from neo4j import GraphDatabase
from dotenv import load_dotenv
load_dotenv()

user = os.getenv("NEO4J_USER")
protocol = os.getenv("NEO4J_PROTOCOL")
password = os.getenv("NEO4J_PASSWORD")
host = os.getenv("NEO4J_HOST")
port = os.getenv("NEO4J_PORT")
db_name = os.getenv("NEO4J_DB")

neo4j_url = f"{protocol}://{host}:{port}"
neo4j_auth = (user, password)

driver = GraphDatabase.driver(neo4j_url, auth=neo4j_auth)
with GraphDatabase.driver(neo4j_url, auth=neo4j_auth) as driver:
driver.verify_connectivity()

def read(cypher, database = 'neo4j'):

records, summary, keys = driver.execute_query(cypher, database_= database)
return records, summary, keys

def write(cypher, database = 'neo4j'):

records, summary, keys = driver.execute_query(cypher, database_= database)
return summary

0 comments on commit d8c88cc

Please sign in to comment.