"""Read-only example for pg-graph with an existing Apache AGE social graph.

Requires the pg_graph Python package, its Cypher grammar dependency, and an
Apache AGE database containing Person vertices and KNOWS edges. Configure
PGHOST, PGPORT, PGDATABASE, PGUSER, PGPASSWORD, and PGGRAPH_GRAPH as appropriate.
The graph topology is cached in memory.
"""
import os
from pg_graph import PGGraph

with PGGraph.connect(
    host=os.environ.get('PGHOST', 'localhost'),
    port=int(os.environ.get('PGPORT', '5432')),
    database=os.environ.get('PGDATABASE', 'postgres'),
    user=os.environ.get('PGUSER', 'postgres'),
    password=os.environ.get('PGPASSWORD', ''),
    graph=os.environ.get('PGGRAPH_GRAPH', 'social'),
) as graph:
    query = """
        MATCH (p:Person)-[:KNOWS*1..3]->(friend:Person)
        WHERE p.name = 'Ada'
        RETURN DISTINCT friend.name
    """
    print(graph.explain(query))
    for row in graph.execute(query):
        print(row)
