Quick Start¶
This guide will get you up and running with Grafeo in just a few minutes.
Create a Database¶
Add Data¶
Use GQL to insert nodes and edges:
with db.session() as session:
# Create nodes
session.execute("""
INSERT (:Person {name: 'Alice', age: 30})
INSERT (:Person {name: 'Bob', age: 25})
INSERT (:Person {name: 'Carol', age: 35})
""")
# Create edges
session.execute("""
MATCH (a:Person {name: 'Alice'}), (b:Person {name: 'Bob'})
INSERT (a)-[:KNOWS {since: 2020}]->(b)
""")
session.execute("""
MATCH (b:Person {name: 'Bob'}), (c:Person {name: 'Carol'})
INSERT (b)-[:KNOWS {since: 2022}]->(c)
""")
let session = db.session()?;
// Create nodes
session.execute(r#"
INSERT (:Person {name: 'Alice', age: 30})
INSERT (:Person {name: 'Bob', age: 25})
INSERT (:Person {name: 'Carol', age: 35})
"#)?;
// Create edges
session.execute(r#"
MATCH (a:Person {name: 'Alice'}), (b:Person {name: 'Bob'})
INSERT (a)-[:KNOWS {since: 2020}]->(b)
"#)?;
session.execute(r#"
MATCH (b:Person {name: 'Bob'}), (c:Person {name: 'Carol'})
INSERT (b)-[:KNOWS {since: 2022}]->(c)
"#)?;
Query Data¶
Retrieve data using pattern matching:
with db.session() as session:
# Find all people
result = session.execute("""
MATCH (p:Person)
RETURN p.name, p.age
ORDER BY p.age
""")
for row in result:
print(f"{row['p.name']} is {row['p.age']} years old")
# Find who Alice knows
result = session.execute("""
MATCH (a:Person {name: 'Alice'})-[:KNOWS]->(friend)
RETURN friend.name
""")
for row in result:
print(f"Alice knows {row['friend.name']}")
# Find friends of friends
result = session.execute("""
MATCH (a:Person {name: 'Alice'})-[:KNOWS]->()-[:KNOWS]->(fof)
RETURN DISTINCT fof.name
""")
for row in result:
print(f"Friend of friend: {row['fof.name']}")
let session = db.session()?;
// Find all people
let result = session.execute(r#"
MATCH (p:Person)
RETURN p.name, p.age
ORDER BY p.age
"#)?;
for row in result {
println!("{} is {} years old",
row.get::<String>("p.name")?,
row.get::<i64>("p.age")?
);
}
// Find who Alice knows
let result = session.execute(r#"
MATCH (a:Person {name: 'Alice'})-[:KNOWS]->(friend)
RETURN friend.name
"#)?;
for row in result {
println!("Alice knows {}", row.get::<String>("friend.name")?);
}
Update Data¶
Modify existing nodes and edges:
Delete Data¶
Remove nodes and edges:
Next Steps¶
- Your First Graph - Build a complete graph application
- GQL Query Language - Learn more about queries
- Python API - Python-specific features
- Rust API - Rust-specific features