mix selecto.gen.parameterized_join (selecto_mix v0.4.6)
Generate existing-join parameterization fragments for Selecto domains.
This task helps add runtime parameters to an existing Selecto join. The join
name must already be present in the domain's joins map, usually because it
was generated from an Ecto association.
Examples
# Generate a basic existing-join parameterization fragment
mix selecto.gen.parameterized_join customer country:string,required
# Generate with field specifications
mix selecto.gen.parameterized_join customer country:string,required --fields company_name:string,country:string
# Generate with join condition template
mix selecto.gen.parameterized_join customer country:string --condition "customers.country = :country"Syntax
Parameter format: name:type[,options]
Types: string, integer, number, numeric, decimal, float, boolean, date, datetime Options: required, default=value, description="text"
Options
--fields- Comma-separated list of fields available from this join (field:type format)--condition- SQL join condition template with parameter placeholders--source-table- Deprecated; existing joins already define their source--output- Output file path (defaults to stdout)
Generated Configuration
Outputs a fragment that you copy into an existing join entry:
# Add these keys to the existing :customer join.
# Keep the generated join's name, type, source, and on keys.
parameters: [
%{name: :country, type: :string, required: true}
],
filters: %{
"country" => %{name: "Country", type: :string}
},
fields: %{
company_name: %{type: :string},
country: %{type: :string}
}For runtime queries, call Selecto.join_parameterize/4:
selecto
|> Selecto.join_parameterize(:customer, "usa", country: "USA")
|> Selecto.select(["customer:usa.company_name"])Do not add a brand-new top-level join only for parameterization. Selecto validates top-level joins against the parent schema's associations.
Usage in Queries
Use dot notation to reference parameterized fields:
# Basic parameterized field reference
"customer:USA.company_name"
# Multiple parameters
"customer:USA:true.company_name"
# String parameters with spaces (quoted)
"customer:'United States'.company_name"