KWriter
KWriter

Reputation: 1184

What would be GQLAlchemy, Python, way to create relationship in graph database?

In Cypher, when I create a relationship, I use CREATE clause. To show that there is a connection between the two cities, I would use something like:

CREATE (:City {name: 'London'})-[:CONNECTED_WITH]->(:City {name: 'Dublin'}); 

How can this be done in Python using GQLAlchemy?

Upvotes: 1

Views: 117

Answers (1)

KWriter
KWriter

Reputation: 1184

Creating relationships is done with methods to() and from() that needs to come after create(). So the example from above would look in Python like this:

from gqlalchemy import Create

query = Create()
        .node(labels="City", name="London")
        .to(relationship_type="CONNECTED_WITH")
        .node(labels="City", name="Dublin")
        .execute()

Upvotes: 1

Related Questions