Skip to main content

Module embed

Module embed 

Source
Expand description

Relationship embedding: fetching related rows for a set of parent rows.

Both the REST and GraphQL surfaces embed related resources, and both do it the same way: take the parent rows already fetched, collect the values of the join column, and issue one query for all of them rather than one query per parent row.

SELECT row_to_json(t) FROM (
    SELECT * FROM "public"."posts" WHERE "user_id" = ANY($1::int4[])
) t

The children are then grouped by that column and attached to the parent rows, so a request embedding two relationships across a page of 25 parents costs three queries, not fifty-one.

Structs§

EmbedPlan
Everything needed to fetch one relationship’s rows for a set of parents.

Functions§

attach_to_parent
Attach grouped children onto a parent row under field_name.
group_by_key
group_from_aggregated
Group related rows by the value of their join column. Build the grouping from rows PostgreSQL has already grouped.
key_to_text
Render a JSON value as the text form used to match join keys.
parent_keys
Collect the distinct, non-null join keys of a set of parent rows.