Selecto.Builder.Subselect (Selecto v0.3.14)
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.
Link to this section Summary
Functions
Build the correlated subquery that fetches related data.
Build a single correlated subquery for a subselect configuration.
Build subselect clauses for the SELECT portion of the query.
Resolve the join condition needed to correlate the subquery with the main query.
Wrap subquery results in the appropriate aggregation function.
Link to this section Functions
build_single_subselect(selecto, subselect_config)
@spec build_single_subselect(Selecto.Types.t(), Selecto.Types.subselect_selector()) :: {Selecto.Types.iodata_with_markers(), Selecto.Types.sql_params()}
Build a single correlated subquery for a subselect configuration.
build_single_subselect(selecto, subselect_config, source_alias)
@spec build_single_subselect( Selecto.Types.t(), Selecto.Types.subselect_selector(), String.t() ) :: {Selecto.Types.iodata_with_markers(), Selecto.Types.sql_params()}
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)
@spec build_subselect_clauses(Selecto.Types.t(), String.t()) :: {[Selecto.Types.iodata_with_markers()], Selecto.Types.sql_params()}
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()}
wrap_in_aggregation(subquery_iodata, subquery_params, format, config)
@spec wrap_in_aggregation( Selecto.Types.iodata_with_markers(), Selecto.Types.sql_params(), Selecto.Types.subselect_format(), Selecto.Types.subselect_selector() ) :: {Selecto.Types.iodata_with_markers(), Selecto.Types.sql_params()}
Wrap subquery results in the appropriate aggregation function.