O'Reilly logo

Building Web Applications with Python and Neo4j by Sumit Gupta

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Running Cypher queries

In this section, we will talk about executing the raw Cypher queries to handle complex requirements and then further converting them into a model and presenting it to the end user.

Cypher queries can be executed by the following two ways:

  • Using the StructuredNode.cypher(query,params) function
  • Using the neomodel.db.cypher_query(query, params) function

In the first option, the query definition needs to be defined within the domain class itself and then it uses StructuredNode.inflate() for creating domain objects from the raw Cypher results.

For example, let's assume that we need to retrieve and print all the male friends of a given node. So we will modify our Model.py and add the following method in the Male class:

def getAllMaleFriends(self): ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required