Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🤖 Sandbox code update #34

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 11 additions & 13 deletions code/python/example.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
# pip3 install neo4j-driver
# pip3 install neo4j
# python3 example.py

from neo4j import GraphDatabase, basic_auth

driver = GraphDatabase.driver(
"neo4j://<HOST>:<BOLTPORT>",
auth=basic_auth("<USERNAME>", "<PASSWORD>"))

cypher_query = '''
MATCH (p:Product)-[:PART_OF]->(:Category)-[:PARENT*0..]->
(:Category {categoryName:$category})
RETURN p.productName as product
'''

with driver.session(database="neo4j") as session:
results = session.read_transaction(
lambda tx: tx.run(cypher_query,
category="Dairy Products").data())
for record in results:
print(record['product'])

driver.close()
with GraphDatabase.driver(
"neo4j://<HOST>:<BOLTPORT>",
auth=("<USERNAME>", "<PASSWORD>")
) as driver:
result = driver.execute_query(
cypher_query,
category="Dairy Products",
database_="neo4j")
for record in result.records:
print(record['product'])