Selecto.EctoAdapter (Selecto v0.3.11)

Ecto integration for Selecto query builder.

This module provides functionality to automatically configure Selecto from Ecto schemas and repositories, making it easy to integrate with Phoenix applications.

usage

Usage

# Configure from Ecto repo and schema
selecto = Selecto.EctoAdapter.configure(MyApp.Repo, MyApp.User)

# With options
selecto = Selecto.EctoAdapter.configure(MyApp.Repo, MyApp.User, 
  joins: [:posts, :comments],
  redact_fields: [:password_hash]
)

# Generate domain from schema
domain = Selecto.EctoAdapter.schema_to_domain(MyApp.User)

Link to this section Summary

Functions

Configure Selecto from an Ecto repository and schema.

Get available associations from an Ecto schema.

Get field information from an Ecto schema.

Generate a Selecto domain configuration from an Ecto schema.

Link to this section Functions

Link to this function

configure(repo, schema, opts \\ [])

Configure Selecto from an Ecto repository and schema.

parameters

Parameters

  • repo - The Ecto repository module (e.g., MyApp.Repo)
  • schema - The Ecto schema module to use as the source table
  • opts - Configuration options

options

Options

  • :joins - List of associations to include as joins (atoms)
  • :redact_fields - List of fields to exclude from queries (atoms)
  • :custom_columns - Map of custom column definitions
  • :custom_filters - Map of custom filter definitions
  • :extensions - List of Selecto extension specs applied during domain build
  • :validate - Whether to validate domain configuration (boolean)
  • :name - Custom name for the domain (string)

examples

Examples

# Basic usage
selecto = Selecto.EctoAdapter.configure(MyApp.Repo, MyApp.User)

# With joins and redacted fields
selecto = Selecto.EctoAdapter.configure(MyApp.Repo, MyApp.User,
  joins: [:posts, :profile],
  redact_fields: [:password_hash, :email]
)

# With custom columns
selecto = Selecto.EctoAdapter.configure(MyApp.Repo, MyApp.User,
  custom_columns: %{
    "full_name" => %{
      name: "Full Name",
      select: {:concat, ["first_name", {:literal, " "}, "last_name"]}
    }
  }
)
Link to this function

get_associations(schema)

Get available associations from an Ecto schema.

Returns a list of association names that can be used in joins.

Link to this function

get_fields(schema)

Get field information from an Ecto schema.

Returns a map with field names and their types.

Link to this function

schema_to_domain(schema, opts \\ [])

Generate a Selecto domain configuration from an Ecto schema.

This function introspects the Ecto schema and generates a compatible domain map for Selecto configuration.

parameters

Parameters

  • schema - The Ecto schema module
  • opts - Configuration options (see configure/3)

returns

Returns

A domain map compatible with Selecto.configure/2