Accompanying code for my talk at the NODES 2022 conference titled: "Building a Python/Neo4j OGM".
Each folder can be seen as a new "branch", where features are added incrementally.
pip install -r requirements.txt
export PYTHONPATH=.$PYTHONPATH
pytest <dir>/tests.py
pytest 00-movie-creation/tests.py
pytest 01-node-class/tests.py
pytest 02-property-attributes/tests.py
pytest 03-manager-match/tests.py
pytest 04-relationship-property-fetch-and-cache/tests.py
pytest 05-prefetch/tests.py
- 00-movie-creation: movie class and hard-coded CREATE statement
- 01-node-class: Property and Node (w/ metaclass) => all subclasses of the
Node
class now have a_properties
attribute with a list of properties they accept - 02-property-attributes: define a Property as required (NB: skipped during the talk)
- 03-manager-match: dynamically build MATCH clause, RETURN statement, object hydration from DB
- 04-relationship-property-fetch-and-cache: define RelationshipProperty and ability to fetch the data
when the field is accessed (ie when using
movie.actors
for instance) - 05-prefetch: ability to prefetch related object during the MATCH query thanks to Cypher map projection
MATCH (node:Movie {title: "Cloud Atlas"})
RETURN node { .* }
MATCH (node:Movie {title: "Cloud Atlas"})
RETURN node { .title, _id: id(node) }
MATCH (node:Movie {title: "Cloud Atlas"})
RETURN node {
.title,
actors: [(node)<-[:ACTED_IN]-(person:Person)
| person { .name }
]
}
MATCH (node:Movie {title: "Cloud Atlas"})
RETURN node {
.title,
actors: [
(node)<-[:ACTED_IN]-(person:Person)
| person {
.name,
directed: [
(person)-[:DIRECTED]->(directed:Movie)
| directed { .* }
]
}
]
}
The code presented here is a simplified version extracted from this project: pentaquark