Skip to content

Commit

Permalink
first program with neo4j
Browse files Browse the repository at this point in the history
  • Loading branch information
TokGrin committed Sep 25, 2024
1 parent cc9c4aa commit 99c5488
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions neo4j firststep/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from neo4j import GraphDatabase

uri = "bolt://localhost:7687" # URI Neo4j (обычно bolt-соединение)
username = "neo4j" # Имя пользователя
password = "password" # Пароль

driver = GraphDatabase.driver(uri, auth=(username, password))

def create_person(tx, name, age):
tx.run("CREATE (p:Person {name: $name, age: $age})", name=name, age=age)

def get_people(tx):
result = tx.run("MATCH (p:Person) RETURN p.name AS name, p.age AS age")
for record in result:
print(f"Name: {record['name']}, Age: {record['age']}")

def clear_database(tx):
tx.run("MATCH (n) DETACH DELETE n")

with driver.session() as session:
session.write_transaction(create_person, "Alice", 30)
session.write_transaction(create_person, "Bob", 24)
print("List of people:")
session.read_transaction(get_people)

driver.close()

0 comments on commit 99c5488

Please sign in to comment.