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 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.
Functions
@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.
@spec build_single_subselect( Selecto.Types.t(), Selecto.Types.subselect_selector(), String.t() ) :: {Selecto.Types.iodata_with_markers(), Selecto.Types.sql_params()}
@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.
@spec build_subselect_clauses(Selecto.Types.t(), String.t()) :: {[Selecto.Types.iodata_with_markers()], Selecto.Types.sql_params()}
@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.
@spec resolve_join_condition_with_path(Selecto.Types.t(), atom()) :: {:ok, Selecto.Types.iodata_with_markers()} | {:error, String.t()}
@spec resolve_join_condition_with_path(Selecto.Types.t(), atom(), String.t()) :: {:ok, Selecto.Types.iodata_with_markers()} | {:error, String.t()}
@spec resolve_join_condition_with_path( Selecto.Types.t(), atom(), String.t(), [atom()] | nil ) :: {:ok, Selecto.Types.iodata_with_markers()} | {:error, String.t()}
@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.