Selecto.Builder.Subselect (Selecto v0.4.5)

Copy Markdown

SQL generation logic for Subselect functionality.

This module handles the construction of correlated subqueries that return aggregated data from related tables as JSON arrays, PostgreSQL arrays, or other aggregate formats.

Summary

Functions

build_correlated_subquery(selecto, subselect_config)

Build the correlated subquery that fetches related data.

build_correlated_subquery(selecto, subselect_config, source_alias)

build_single_subselect(selecto, subselect_config)

Build a single correlated subquery for a subselect configuration.

build_single_subselect(selecto, subselect_config, source_alias)

build_subselect_clauses(selecto)

@spec build_subselect_clauses(Selecto.Types.t()) ::
  {[Selecto.Types.iodata_with_markers()], Selecto.Types.sql_params()}

Build subselect clauses for the SELECT portion of the query.

Returns a list of SQL fragments that can be included in the main SELECT clause. Each subselect becomes a correlated subquery that aggregates related data.

build_subselect_clauses(selecto, source_alias)

resolve_join_condition(selecto, target_schema)

@spec resolve_join_condition(Selecto.Types.t(), atom()) ::
  {:ok, {String.t(), String.t()}} | {:error, String.t()}

Resolve the join condition needed to correlate the subquery with the main query.

resolve_join_condition_with_path(selecto, target_schema)

@spec resolve_join_condition_with_path(Selecto.Types.t(), atom()) ::
  {:ok, Selecto.Types.iodata_with_markers()} | {:error, String.t()}

resolve_join_condition_with_path(selecto, target_schema, source_alias)

@spec resolve_join_condition_with_path(Selecto.Types.t(), atom(), String.t()) ::
  {:ok, Selecto.Types.iodata_with_markers()} | {:error, String.t()}

resolve_join_condition_with_path(selecto, target_schema, source_alias, explicit_join_path)

@spec resolve_join_condition_with_path(
  Selecto.Types.t(),
  atom(),
  String.t(),
  [atom()] | nil
) ::
  {:ok, Selecto.Types.iodata_with_markers()} | {:error, String.t()}

wrap_in_aggregation(subquery_iodata, subquery_params, format, config)

Wrap subquery results in the appropriate aggregation function.