Skip to content

Fragments and views

Map a node with a NodeFragment, and compose fragments and relationships into a GraphView, which loads in one statement:

from typing import Annotated
from drivine import GraphView, NodeFragment, NodeId, Relationship, RelationshipFragment, Root, TargetNode
class Person(NodeFragment, labels=["Person"]):
uuid: Annotated[str, NodeId()]
name: str
bio: str | None = None
class Organization(NodeFragment, labels=["Organization"]):
uuid: Annotated[str, NodeId()]
name: str
class WorkHistory(RelationshipFragment): # a relationship's properties, and the node it leads to
start_date: str
role: str
target: Annotated[Organization, TargetNode()]
class PersonCareer(GraphView):
person: Annotated[Person, Root()]
employment_history: Annotated[list[WorkHistory], Relationship("WORKS_FOR")] = []
gom = drivine.graph_object_manager() # from DrivineAssembly, or StatelessGraphObjectManager(pm)
career = await gom.load(PersonCareer, uuid)
leads = await gom.load_all(PersonCareer, "n.bio CONTAINS $text", {"text": "Lead"}) # Cypher over the root, n
total = await gom.count(Person)

On Oracle, Postgres and SQLite a node is found by its id as the store’s range index and uniqueness constraint over the id are made, so a lookup by id reads that index, and a date id is one node however often it is saved. On every store, Neo4j, Memgraph and FalkorDB too, an id given as text to load, update, patch, delete or edges is read as the NodeId field’s annotated type, and bound as a save writes the field, as drivine4j reads it: "6" finds the node whose int id is 6, ISO 8601 text the node whose date, datetime or time id is that value (in the extended form a save writes, of a real day and an hour before 24), "true" the node whose bool id is true, and a UUID’s text the node whose UUID id it is. A str id is the text given, so "6" doesn’t find a node of the same labels whose id is the number 6. Text that is no value of the type, such as "abc" for an int id, or "6.0", which isn’t a whole number’s text, finds no node: nothing is run, and a DEBUG line on the drivine.node_ids logger says why. A None id finds none either, and runs nothing. Before, Neo4j, Memgraph and FalkorDB compared the id as it was given, so "5" never found a node whose int id is 5.

A node whose id Oracle, Postgres or SQLite holds as a temporal value, such as a date another library or a Cypher date(...) wrote, is refused by name when it is loaded by a class that declares the id a str, a number or any other type that isn’t temporal, or a union that would load the id’s text as text: one with a str member (str | date), or one with no temporal member (int | None). Its id would load as its text, which no lookup by the id finds, so saving it back would make a second node. The message says what to declare instead: Event's NodeId id is declared a str, but the node whose id is '2026-01-05' holds it as a date: declare id as a date to load it. A temporal id, or a union whose temporal member loads it (date | None, int | date), loads the value, unless saving that value back would write a different one: a date id over a stored datetime or localdatetime, a datetime id over a date, a time below the microsecond, which Python can’t hold, or a timedelta id over a duration of months or one written another way (P1M, PT24H). Those are refused by name too, and the message names the type to declare. An id declared Any loads as the text of the temporal value the store holds, and a save writes it back as that value, so the node stays one node while the id is unchanged. A property declared Any is saved back the same way.