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): ...

Get Building Web Applications with Python and Neo4j now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.