Grouped reads
Group a fragment’s nodes by keys, with numbers about each group, in one statement:
from drivine import avg, count, hop, key, path_key, refs
q = refs(Review)top = await gom.groups.load( Review, keys={"page": key(q.page)}, # or path_key(Page, [hop("REVIEWS")]): the node aggregates={"votes": count(q.helpful.eq(True)), "rating": avg(q.rating)}, where=q.published.is_not_null(), having=[("votes", "gte", 3)], order_by=[("votes", "desc")], limit=10,)# [{"page": "/pricing", "votes": 12, "rating": 4.5}, ...]
await gom.groups.count_by(Review, "page") # {"/pricing": 14, ...}Aggregates are count, sum_, avg, min_ and max_, each with an optional filter. Ties in an order are broken by
the keys, so a page of groups is the same every time. A path key’s groups are ordered by its node’s id, so a path key to
a class with no NodeId field is refused, before anything is run, on every store. On the SQL stores a key is ordered as Cypher orders it (a text,
then a boolean, then a number, no value last), a date by its
moment, and min_ and max_ take a value of any kind, a text or a date as well as a number, read back as the type its
field declares. A text stored as "" is kept by min_ and max_, as Cypher keeps it, on Oracle too.
- Models are Pydantic. A loaded fragment is validated, so a bad value fails at the load.
- The annotation says what a relationship holds: a fragment, a relationship fragment or a view, one or a list. A
single relationship typed without
Noneis required, so only roots that have it load;Person | Noneis optional. A list is required withRelationship(..., required=True). - Properties are stored in camel case, as TypeScript and JVM models store them:
start_dateasstartDate.GraphProperty("name")names one, andproperty_names="as_written"keeps a class’s fields as they are written. - A subclass is loaded as itself. A fragment’s labels are inherited, and a node loads as the most specific subclass whose labels it carries.
- Recursion:
Relationship("HAS_LOCATION", max_depth=3)on a list of the view’s own class expands three levels;depth={"sub_locations": 5}overrides it for one load. - More markers:
GraphPath([hop(...), ...])for the nodes at the end of several hops,CountandAggregatecomputed in the query,SortedBy,ReadOnly,Transient,NodeStamp,NodeLabels,PropertyBag,JsonPacked,NullAsDefaultandEmptyWhenAbsent, as in TypeScript’s Drivine. - A path in an order: one hop of a
GraphPathmay name an order, a property of the node it reaches by its stored name (sentAtfor a fieldsent_at), lowest first unlessascendingisFalse:hop("HAS_MESSAGE", Direction.OUTGOING, "Message", "sentAt"). A list then holds its targets in the order of the first node of that hop that leads to each, and a single field holds the target the first such node leads to. A node of the ordered hop without the property comes last, whichever way the path is read. Targets whose first nodes hold equal values come in no set order. A text of digits such as'0100'is ordered as text, and an empty text as a text, the lowest one. On Neo4j and the SQL stores a date is ordered by its moment, an offset’s included, not by its text. Where the property holds values of several kinds, Neo4j, Memgraph and the SQL stores order them by kind as Cypher’s ORDER BY does: lowest first a map, a list, a temporal value, a text, a boolean, then a number, and the other way highest first. On Neo4j and Memgraph the path is sorted by the engine’s own ORDER BY. FalkorDB orders them as its own ORDER BY does. A group key’s path names no order:path_keyrefuses one. - A set field is stored as a list of its items, sorted where they order (as the set iterates where they don’t), and
a
JsonPackedone packed so: a set is written alike in every process, whatever order it iterates in.patchwrites one so too, andedges.relatewrites a set property so. One that 0.1.0 wrote, in the order it iterated in, loads andupdatesaves it, but until a save writes it again awherethat compares the whole set, which it writes sorted, doesn’t find it on the graph engines (on Postgres and Oracle a whole-setwhereon a set that isn’tJsonPackeddoesn’t find it either way), and on Neo4j a save givenfrom_of aJsonPackedone is refused. - A flat
PropertyBag(flat=True)stores each entry under its bare key and loads every property no field or other bag is stored under. A save refuses, before it writes anything, an entry whose key a field (the id among them) is stored under, one under another bag’s prefix, or one beginning__drivine., Drivine’s own, such as the stamp.
The statements are TypeScript’s, character for character: the tests check them against those TypeScript’s Drivine writes for the same models.

