Expand description
QuerySet: a lazy, immutable query over one model.
Builder methods consume and return the queryset and never perform I/O;
terminal methods (all, first, get, count, exists, update, …)
run the compiled QueryPlan on the queryset’s Db. Clone a queryset
to branch from a common base.
Mistakes that can only be detected while building (an unknown annotation name, a filter on a window function) are remembered and returned by the next terminal method, so builder chains stay infallible.
§Annotations
annotate and alias name an
expression; later filter / order_by / project calls refer to it with
Expr::col("name") and the expression is inlined (PostgreSQL does not
allow output aliases in WHERE / HAVING). A filter on an aggregate
annotation becomes HAVING; when the projection contains aggregates the
remaining projected columns become the GROUP BY and the model’s default
ordering is dropped, as in Django.
Structs§
- Cursor
Page - One page of a
QuerySet::cursor_pageresult. - Page
- One page of a
QuerySet::paginateresult. - Prefetch
prefetch_relatedrequest: a relation and, optionally, the queryset used to load the targets (to filter them, order them or use another handle).- Query
Set - Lazy query over model
M. - Relation
- A foreign key of model
Mpointing atT, together with access to its slot inM, so loaders can store the related object in the struct: