Skip to content

graflo.db.cypher.scan

Read every relationship between two labels, whatever its endpoints' keys.

Functions:

all_relationships_query(source_label, target_label, relation, *, limit=None)

Every relation relationship from a source_label to a target_label node.

Returns the source node, the target node and the relationship, in that order, as entities; with no relation, relationships of every type.

Source code in graflo/db/cypher/scan.py
def all_relationships_query(
    source_label: str,
    target_label: str,
    relation: str | None,
    *,
    limit: int | None = None,
) -> str:
    """Every ``relation`` relationship from a ``source_label`` to a ``target_label`` node.

    Returns the source node, the target node and the relationship, in that
    order, as entities; with no *relation*, relationships of every type.
    """
    rel = f":{cypher_name(relation)}" if relation else ""
    query = (
        f"MATCH (source:{cypher_name(source_label)})-[r{rel}]->"
        f"(target:{cypher_name(target_label)}) RETURN source, target, r"
    )
    return query if limit is None else f"{query} LIMIT {int(limit)}"