Selecto.Fields (Selecto v0.3.8)

Field access and resolution operations for Selecto.

This module provides functions to access and resolve field information from a Selecto configuration, including custom columns, joins, filters, and field suggestions.

Link to this section Summary

Functions

Get all available fields across all joins and the source table.

Get all columns available in the query.

Get the domain configuration.

Get custom domain data.

Get normalized extension specs loaded for this Selecto instance.

Get field information by field name.

Get field suggestions for autocomplete or error recovery.

Get all filters defined in the domain configuration.

Get all join configurations for the query.

Enhanced field resolution with disambiguation and error handling.

Get the current query set (selected fields, filters, etc.).

Get the source table name.

Link to this section Functions

Link to this function

available_fields(selecto)

@spec available_fields(Selecto.Types.t()) :: [String.t()]

Get all available fields across all joins and the source table.

examples

Examples

fields = Selecto.Fields.available_fields(selecto)
# => ["id", "name", "email", "posts[title]", ...]
Link to this function

columns(selecto)

@spec columns(Selecto.Types.t()) :: map()

Get all columns available in the query.

Returns a map of all columns from the source table and joined tables.

examples

Examples

columns = Selecto.Fields.columns(selecto)
# => %{id: %{name: "id", type: :integer, ...}, ...}
Link to this function

domain(selecto)

@spec domain(Selecto.Types.t()) :: Selecto.Types.domain()

Get the domain configuration.

examples

Examples

domain = Selecto.Fields.domain(selecto)
# => %{name: "User", source: %{...}, ...}
Link to this function

domain_data(selecto)

@spec domain_data(Selecto.Types.t()) :: term()

Get custom domain data.

examples

Examples

data = Selecto.Fields.domain_data(selecto)
Link to this function

extensions(selecto)

@spec extensions(Selecto.Types.t()) :: [{module(), keyword()}]

Get normalized extension specs loaded for this Selecto instance.

Link to this function

field(selecto, field_name)

@spec field(Selecto.Types.t(), Selecto.Types.field_name()) :: map() | nil

Get field information by field name.

Supports custom columns, joined fields, and regular fields. Handles various field name formats and provides compatibility mappings.

examples

Examples

field_info = Selecto.Fields.field(selecto, "customer[name]")
# => %{name: "name", field: "name", requires_join: :customer, ...}
Link to this function

field_suggestions(selecto, partial_name)

@spec field_suggestions(Selecto.Types.t(), String.t()) :: [String.t()]

Get field suggestions for autocomplete or error recovery.

examples

Examples

suggestions = Selecto.Fields.field_suggestions(selecto, "cust")
# => ["customer[id]", "customer[name]", "customer[email]"]
Link to this function

filters(selecto)

@spec filters(Selecto.Types.t()) :: %{required(String.t()) => term()}

Get all filters defined in the domain configuration.

examples

Examples

filters = Selecto.Fields.filters(selecto)
# => %{"active" => %{name: "Active", type: "boolean", ...}}
@spec joins(Selecto.Types.t()) :: map()

Get all join configurations for the query.

examples

Examples

joins = Selecto.Fields.joins(selecto)
# => %{posts: %{type: :left, ...}, ...}
Link to this function

resolve_field(selecto, field_name)

@spec resolve_field(Selecto.Types.t(), Selecto.Types.field_name()) ::
  {:ok, map()} | {:error, term()}

Enhanced field resolution with disambiguation and error handling.

Provides detailed field information and helpful error messages.

examples

Examples

case Selecto.Fields.resolve_field(selecto, "name") do
  {:ok, field_info} -> # use field_info
  {:error, reason} -> # handle error
end

Get the current query set (selected fields, filters, etc.).

examples

Examples

query_set = Selecto.Fields.set(selecto)
# => %{selected: ["id", "name"], filtered: [...], ...}
Link to this function

source_table(selecto)

@spec source_table(Selecto.Types.t()) :: Selecto.Types.table_name() | nil

Get the source table name.

examples

Examples

table = Selecto.Fields.source_table(selecto)
# => "users"