Selecto.Subfilter.Registry (Selecto v0.3.12)
Registry system for managing multiple subfilters with strategy selection and optimization.
The Registry handles:
- Multiple subfilter registration and management
- Strategy selection (EXISTS, IN, ANY, ALL) based on query patterns
- Performance optimization through join analysis
- Conflict detection and resolution
- SQL generation coordination
examples
Examples
iex> registry = Selecto.Subfilter.Registry.new(:film_domain)
iex> registry = Registry.add_subfilter(registry, "film.rating", "R")
iex> registry = Registry.add_subfilter(registry, "film.category.name", "Action")
iex> Registry.generate_sql(registry, base_query)
{:ok, optimized_query_with_subfilters}
Link to this section Summary
Functions
Add compound subfilter operations (AND/OR).
Add a subfilter to the registry.
Get comprehensive analysis of all subfilters in the registry.
Generate SQL for all subfilters in the registry.
Create a new subfilter registry for the specified domain.
Override the strategy for a specific subfilter.
Remove a subfilter from the registry.
Link to this section Types
compound_operation()
@type compound_operation() :: %{type: :and | :or, subfilter_ids: [String.t()]}
@type t() :: %Selecto.Subfilter.Registry{ base_table: atom() | nil, compound_ops: [compound_operation()], domain_name: atom() | map(), join_resolutions: %{ required(String.t()) => Selecto.Subfilter.JoinPathResolver.JoinResolution.t() }, optimization_hints: keyword(), strategy_overrides: %{required(String.t()) => atom()}, subfilters: %{required(String.t()) => Selecto.Subfilter.Spec.t()} }
Link to this section Functions
add_compound(registry, compound_type, subfilter_specs, opts \\ [])
@spec add_compound( t(), :and | :or, [{String.t(), any()}] | [{String.t(), any(), keyword()}], keyword() ) :: {:ok, t()} | {:error, Selecto.Subfilter.Error.t()}
Add compound subfilter operations (AND/OR).
examples
Examples
add_compound(registry, :and, [
{"film.rating", "R"},
{"film.release_year", {">", 2000}}
])
add_subfilter(registry, relationship_path, filter_spec, opts \\ [])
@spec add_subfilter(t(), String.t(), any(), keyword()) :: {:ok, t()} | {:error, Selecto.Subfilter.Error.t()}
Add a subfilter to the registry.
examples
Examples
add_subfilter(registry, "film.rating", "R")
add_subfilter(registry, "film.category.name", ["Action", "Drama"], strategy: :in)
add_subfilter(registry, "film", {:count, ">", 5}, id: "film_count_filter")
analyze(registry)
@spec analyze(t()) :: %{ subfilter_count: non_neg_integer(), join_complexity: atom(), strategy_distribution: %{required(atom()) => non_neg_integer()}, performance_score: float(), optimization_suggestions: [String.t()] }
Get comprehensive analysis of all subfilters in the registry.
Returns information about join patterns, strategy selections, performance implications, and optimization opportunities.
generate_sql(registry, base_query)
@spec generate_sql(t(), String.t()) :: {:ok, String.t(), [any()]} | {:error, Selecto.Subfilter.Error.t()}
Generate SQL for all subfilters in the registry.
This coordinates with the SQL generation system to produce optimized subquery SQL that integrates with the main query.
new(domain_name, opts \\ [])
Create a new subfilter registry for the specified domain.
parameters
Parameters
domain_name- Domain configuration to use (e.g., :film_domain)opts- Options including :base_table, :optimization_hints
override_strategy(registry, subfilter_id, strategy)
@spec override_strategy(t(), String.t(), atom()) :: {:ok, t()} | {:error, Selecto.Subfilter.Error.t()}
Override the strategy for a specific subfilter.
Useful for performance tuning when the automatic strategy selection doesn't produce optimal results.
remove_subfilter(registry, subfilter_id)
Remove a subfilter from the registry.