Selecto.Fields (Selecto v0.4.5)

Copy Markdown

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.

Summary

Functions

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

Get all columns available in the query.

Get configured detail-row actions for the domain.

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.

Functions

available_fields(selecto)

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

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

Examples

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

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

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

detail_actions(selecto)

@spec detail_actions(Selecto.Types.t()) :: %{optional(atom() | String.t()) => map()}

Get configured detail-row actions for the domain.

domain(selecto)

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

Get the domain configuration.

Examples

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

domain_data(selecto)

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

Get custom domain data.

Examples

data = Selecto.Fields.domain_data(selecto)

extensions(selecto)

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

Get normalized extension specs loaded for this Selecto instance.

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

field_info = Selecto.Fields.field(selecto, "customer.name")
# => %{name: "name", field: "name", requires_join: :customer, ...}

field_suggestions(selecto, partial_name)

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

Get field suggestions for autocomplete or error recovery.

Examples

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

filters(selecto)

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

Get all filters defined in the domain configuration.

Examples

filters = Selecto.Fields.filters(selecto)
# => %{"active" => %{name: "Active", type: "boolean", ...}}

joins(selecto)

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

Get all join configurations for the query.

Examples

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

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

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

set(selecto)

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

Examples

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

source_table(selecto)

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

Get the source table name.

Examples

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