Selecto.SelectionShape (Selecto v0.3.15)

Structured selection helpers for building and materializing nested result shapes.

This module lets callers provide a list/tuple selection shape and receive rows back in that same nested shape via execute_shape/2.

Nested lists/tuples that exclusively reference fields from a single joined schema are treated as subselect nodes and compiled to json_agg correlated subqueries.

Link to this section Summary

Functions

Execute a shape query and materialize rows into the configured nested shape.

Compile a nested selection shape into regular Selecto selectors + subselect specs.

Materialize DB rows according to a compiled shape plan.

Link to this section Types

Link to this type

shape_input()

@type shape_input() :: list() | tuple()

Link to this section Functions

Link to this function

execute_shape(selecto, opts \\ [])

@spec execute_shape(
  Selecto.t(),
  keyword()
) :: {:ok, list()} | {:error, Selecto.Error.t()}

Execute a shape query and materialize rows into the configured nested shape.

Returns {:ok, shaped_rows}.

Link to this function

select_shape(selecto, shape)

@spec select_shape(Selecto.t(), shape_input()) :: Selecto.t()

Compile a nested selection shape into regular Selecto selectors + subselect specs.

The generated execution plan is stored on selecto.set.selection_shape and can be used with execute_shape/2.

Link to this function

shape_rows(rows, map)

@spec shape_rows(list(), map()) :: list()

Materialize DB rows according to a compiled shape plan.