Skip to content

Commit

Permalink
Adds examples page
Browse files Browse the repository at this point in the history
  • Loading branch information
jackboyla committed Jun 10, 2024
1 parent 346a044 commit 3d7ebae
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ RETURN A.club, B.club
""")
```

See [examples.md](examples.md) for more!

### Example Usage with SQL

Create your own "Sqlite for Neo4j"! This example uses [grand-graph](https://github.com/aplbrain/grand) to run queries in SQL:
Expand Down Expand Up @@ -81,6 +83,7 @@ RETURN
| Graph mutations (e.g. `DELETE`, `SET`,...) | 🛣 | |
| `DISTINCT` | ✅ Thanks @jackboyla! | |
| `ORDER BY` | ✅ Thanks @jackboyla! | |
| Aggregation functions (`COUNT`, `SUM`, `MIN`, `MAX`, `AVG`) | ✅ Thanks @jackboyla! | |

| | | |
| -------------- | -------------- | ---------------- |
Expand Down
66 changes: 66 additions & 0 deletions examples.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@

## Multigraph

```python
from grandcypher import GrandCypher
import networkx as nx

host = nx.MultiDiGraph()
host.add_node("a", name="Alice", age=25)
host.add_node("b", name="Bob", age=30)
host.add_edge("a", "b", __labels__={"paid"}, amount=12, date="12th June")
host.add_edge("b", "a", __labels__={"paid"}, amount=6)
host.add_edge("b", "a", __labels__={"paid"}, value=14)
host.add_edge("a", "b", __labels__={"friends"}, years=9)
host.add_edge("a", "b", __labels__={"paid"}, amount=40)

qry = """
MATCH (n)-[r:paid]->(m)
RETURN n.name, m.name, r.amount
"""
res = GrandCypher(host).run(qry)
print(res)

'''
{
'n.name': ['Alice', 'Bob'],
'm.name': ['Bob', 'Alice'],
'r.amount': [{(0, 'paid'): 12, (1, 'friends'): None, (2, 'paid'): 40}, {(0, 'paid'): 6, (1, 'paid'): None}]
}
'''
```

## Aggregation Functions

```python
from grandcypher import GrandCypher
import networkx as nx

host = nx.MultiDiGraph()
host.add_node("a", name="Alice", age=25)
host.add_node("b", name="Bob", age=30)
host.add_edge("a", "b", __labels__={"paid"}, amount=12, date="12th June")
host.add_edge("b", "a", __labels__={"paid"}, amount=6)
host.add_edge("b", "a", __labels__={"paid"}, value=14)
host.add_edge("a", "b", __labels__={"friends"}, years=9)
host.add_edge("a", "b", __labels__={"paid"}, amount=40)

qry = """
MATCH (n)-[r:paid]->(m)
RETURN n.name, m.name, SUM(r.amount)
"""
res = GrandCypher(host).run(qry)
print(res)

'''
{
'n.name': ['Alice', 'Bob'],
'm.name': ['Bob', 'Alice'],
'SUM(r.amount)': [{'paid': 52, 'friends': 0}, {'paid': 6}]
}
'''
```




0 comments on commit 3d7ebae

Please sign in to comment.