Selecto.Config.OverlayDSL (Selecto v0.4.3)

A DSL (Domain-Specific Language) for defining overlay configurations.

This module provides a clean, declarative syntax for customizing Selecto domains through overlay files. Instead of manually constructing maps, you can use macros like defcolumn, deffilter, deffunction, defdetail_action, defcte, defvalues, defsubquery, defjoin, defschema, defschema_assoc, and defsource_assoc along with module attributes.

usage

Usage

defmodule MyApp.SelectoDomains.Overlays.ProductDomainOverlay do
  use Selecto.Config.OverlayDSL,
    # Selecto.Extensions.PostGIS is provided by the :selecto_postgis package
    extensions: [Selecto.Extensions.PostGIS]

  # Module attributes for common configurations
  @redactions [:internal_notes, :cost_price]

  # Column customizations
  defcolumn :price do
    label "Product Price"
    format :currency
    aggregate_functions [:sum, :avg, :min, :max]
  end

  defcolumn :description do
    label "Product Description"
    max_length 100
  end

  # Custom filters
  deffilter "price_range" do
    name "Price Range"
    type :string
    description "Filter products by price range (e.g., '10-100')"
  end

  deffilter "in_stock" do
    name "In Stock"
    type :boolean
    description "Show only items currently in stock"
  end

  # Named query members
  defcte :active_products do
    query &__MODULE__.active_products_cte/1
    columns ["id", "name"]
    join [owner_key: :id, related_key: :id, fields: :infer]
  end

  defvalues :status_lookup do
    rows [["active", "Active"], ["archived", "Archived"]]
    columns ["status", "label"]
    as "status_lookup"
    join [owner_key: :status, related_key: :status]
  end

  defsubquery :high_value_orders do
    query &__MODULE__.high_value_orders_subquery/1
    type :inner
    on [%{left: "id", right: "customer_id"}]
  end
end

available-directives

Available Directives

module-attributes

Module Attributes

  • @redactions - List of field atoms to redact from queries

jsonb-schema-with-defjsonb_schema

JSONB Schema (with defjsonb_schema)

Define structured schemas for JSONB columns to enable typed access, filtering, and display:

defjsonb_schema :attributes do
  field :color, :string, label: "Color"
  field :weight, :decimal, label: "Weight (kg)", precision: 2
  field :organic, :boolean, label: "Organic"
  field :certifications, {:array, :string}, label: "Certifications"
  field :dimensions, :object do
    field :width, :decimal, label: "Width"
    field :height, :decimal, label: "Height"
  end
end

Supported types: :string, :integer, :decimal, :boolean, :date, :datetime, {:array, type}, :object (with nested fields)

column-directives-within-defcolumn

Column Directives (within defcolumn)

filter-directives-within-deffilter

Filter Directives (within deffilter)

  • name/1 - Human-readable filter name
  • type/1 - Filter type (:string, :integer, :boolean, :date, etc.)
  • description/1 - Help text for the filter
  • required/1 - Whether filter is required (boolean)
  • default/1 - Default value for the filter
  • options/1 - List of valid options for select-type filters

detail-action-macros

Detail Action Macros

  • defdetail_action id do ... end - Define a detail-row action under detail_actions
  • defpopup id do ... end - Define a modal detail-row action under detail_actions

query-member-macros

Query Member Macros

  • defcte id do ... end - Define a named CTE preset under query_members.ctes
  • defvalues id do ... end - Define a named VALUES preset under query_members.values
  • defsubquery id do ... end - Define a named subquery-join preset under query_members.subqueries
  • deflateral id do ... end - Define a named LATERAL preset under query_members.laterals
  • defunnest id do ... end - Define a named UNNEST preset under query_members.unnests

function-macros

Function Macros

  • deffunction id do ... end - Define a named UDF spec under functions

domain-registry-macros

Domain Registry Macros

  • defjoin id, config - Define a top-level join entry under joins
  • defschema id, config - Define a top-level schema entry under schemas
  • defschema_assoc schema_id, assoc_id, config - Define a schema associations entry
  • defsource_assoc id, config - Define a root source.associations entry

query-member-directives

Query Member Directives

examples

Examples

basic-column-customization

Basic Column Customization

defcolumn :price do
  label "Product Price"
  format :currency
  precision 2
  aggregate_functions [:sum, :avg]
end

complex-filter

Complex Filter

deffilter "status" do
  name "Order Status"
  type :string
  description "Filter by order status"
  options ["pending", "shipped", "delivered", "cancelled"]
  default "pending"
end

using-redactions

Using Redactions

@redactions [:password, :secret_key, :internal_notes]

computed-properties

Computed Properties

defcolumn :total_value do
  label "Total Value"
  format :currency
  aggregate_functions [:sum]
  computed true
end

Link to this section Summary

Functions

Sets the allowed aggregate functions for a column.

Sets the allowed call sites for a UDF registration.

Adds an argument definition to a UDF registration.

Sets the UNNEST array field/expression for named UNNEST members.

Sets the SQL alias/table name for named VALUES members.

Sets recursive CTE base query function.

Sets declared columns for CTE/VALUES query members.

Marks a column as computed (not from database).

Alias for rows/1 in named VALUES members.

Sets the default value for the filter.

Defines a column customization.

Defines a named CTE preset for Selecto.with_cte/2.

Defines a detail-row action.

Defines a custom filter.

Defines a named UDF specification.

Defines a join configuration under the top-level joins registry.

Defines a JSONB schema for a JSONB column, enabling typed field access, filtering, and display of structured JSON data.

Defines a named LATERAL preset for Selecto.with_lateral/2.

Defines a modal detail-row action.

Defines a schema configuration under the top-level schemas registry.

Defines an association under a schema entry in schemas.

Defines a root source association under source.associations.

Defines a named subquery preset for Selecto.with_subquery/2.

Defines a named UNNEST preset for Selecto.with_unnest/2.

Defines a named VALUES preset for Selecto.with_values/2.

Sets CTE dependency names.

Sets the filter description/help text.

Defines a field within a JSONB schema.

Sets whether the column is filterable.

Sets the display format for a column.

Sets join options for query member auto-join behavior.

Sets explicit join id for named subquery members.

Sets the join type for named LATERAL members.

Sets named subquery kind (:join currently supported).

Sets the human-readable label for a column or filter.

Alias for source/1 in named LATERAL members.

Sets the maximum display length for string columns.

Sets the human-readable name for a filter.

Sets ON conditions for named subquery members.

Sets the valid options for a select-type filter.

Sets ordinality alias for named UNNEST members.

Sets a payload map for a detail-row action.

Sets the numeric precision for decimal columns.

Sets a query builder function for named query members.

Sets recursive CTE recursive query function.

Sets whether the filter is required.

Sets required fields for a detail-row action.

Sets the declared return type or return metadata for a UDF registration.

Sets VALUES rows for a named defvalues member.

Sets whether the column is sortable.

Sets a source expression for named LATERAL members.

Sets the SQL function name for a UDF registration.

Sets the filter type.

Link to this section Functions

Link to this macro

aggregate_functions(value)

(macro)

Sets the allowed aggregate functions for a column.

Options: :sum, :avg, :count, :min, :max

Link to this macro

allowed_in(value)

(macro)

Sets the allowed call sites for a UDF registration.

Link to this macro

arg(name, type, opts \\ [])

(macro)

Adds an argument definition to a UDF registration.

Link to this macro

array_field(value)

(macro)

Sets the UNNEST array field/expression for named UNNEST members.

Link to this macro

as(value)

(macro)

Sets the SQL alias/table name for named VALUES members.

Link to this macro

base_query(value)

(macro)

Sets recursive CTE base query function.

Link to this macro

columns(value)

(macro)

Sets declared columns for CTE/VALUES query members.

Link to this macro

computed(value)

(macro)

Marks a column as computed (not from database).

Link to this macro

data(value)

(macro)

Alias for rows/1 in named VALUES members.

Link to this macro

default(value)

(macro)

Sets the default value for the filter.

Link to this macro

defcolumn(column_name, list)

(macro)

Defines a column customization.

example

Example

defcolumn :price do
  label "Product Price"
  format :currency
  aggregate_functions [:sum, :avg]
end
Link to this macro

defcte(cte_id, list)

(macro)

Defines a named CTE preset for Selecto.with_cte/2.

example

Example

defcte :active_customers do
  query &__MODULE__.active_customers_cte/1
  columns ["id", "name"]
  join [owner_key: :id, related_key: :id, fields: :infer]
end
Link to this macro

defdetail_action(action_id, list)

(macro)

Defines a detail-row action.

example

Example

defdetail_action :customer_profile do
  name("Customer Profile")
  description("Open the customer profile in a new tab")
  type(:external_link)
  required_fields([:customer_id])
  payload(%{url_template: "https://app.example.test/customers/{{customer_id}}"})
end
Link to this macro

deffilter(filter_name, list)

(macro)

Defines a custom filter.

example

Example

deffilter "price_range" do
  name "Price Range"
  type :string
  description "Filter by price range"
end
Link to this macro

deffunction(function_id, list)

(macro)

Defines a named UDF specification.

Link to this macro

defjoin(join_id, join_config)

(macro)

Defines a join configuration under the top-level joins registry.

example

Example

defjoin :initiative, %{
  type: :left,
  schema: MyApp.Initiative,
  owner_key: :initiative_id,
  related_key: :id
}
Link to this macro

defjsonb_schema(column_name, list)

(macro)

Defines a JSONB schema for a JSONB column, enabling typed field access, filtering, and display of structured JSON data.

example

Example

defjsonb_schema :attributes do
  field :color, :string, label: "Color"
  field :weight, :decimal, label: "Weight (kg)", precision: 2
  field :organic, :boolean, label: "Organic"
  field :origin_country, :string, label: "Country of Origin"
  field :certifications, {:array, :string}, label: "Certifications"
  field :dimensions, :object do
    field :width, :decimal, label: "Width"
    field :height, :decimal, label: "Height"
    field :depth, :decimal, label: "Depth"
  end
end

supported-field-types

Supported Field Types

  • :string - Text values
  • :integer - Whole numbers
  • :decimal - Decimal numbers (supports precision option)
  • :boolean - True/false values
  • :date - Date values (ISO 8601 format)
  • :datetime - DateTime values (ISO 8601 format)
  • {:array, type} - Arrays of the specified type
  • :object - Nested object (use nested field calls)

field-options

Field Options

  • label - Human-readable label for display
  • precision - Decimal precision (for :decimal type)
  • required - Whether the field is required (default: false)
  • default - Default value for the field
  • filterable - Whether the field can be filtered (default: true)
  • sortable - Whether the field can be sorted (default: true)
  • format - Display format (:currency, :percentage, etc.)
Link to this macro

deflateral(lateral_id, list)

(macro)

Defines a named LATERAL preset for Selecto.with_lateral/2.

example

Example

deflateral :tag_expansion do
  source {:unnest, ""selecto_root"."tags""}
  as "tag_expansion"
  join_type :inner
end
Link to this macro

defpopup(action_id, list)

(macro)

Defines a modal detail-row action.

This is a convenience wrapper around defdetail_action that defaults type to :modal.

Link to this macro

defschema(schema_id, schema_config)

(macro)

Defines a schema configuration under the top-level schemas registry.

example

Example

defschema :initiative, %{
  source_table: "initiatives",
  columns: %{id: %{type: :integer}, name: %{type: :string}}
}
Link to this macro

defschema_assoc(schema_id, association_id, association_config)

(macro)

Defines an association under a schema entry in schemas.

example

Example

defschema_assoc(:bundle_parent_load, :split_parent_load, %{
  queryable: :split_parent_load,
  field: :split_parent_load,
  owner_key: :split_parent_id,
  related_key: :id
})
Link to this macro

defsource_assoc(association_id, association_config)

(macro)

Defines a root source association under source.associations.

example

Example

defsource_assoc(:bundle_parent_load, %{
  queryable: :bundle_parent_load,
  field: :bundle_parent_load,
  owner_key: :bundle_parent_id,
  related_key: :id
})
Link to this macro

defsubquery(subquery_id, list)

(macro)

Defines a named subquery preset for Selecto.with_subquery/2.

example

Example

defsubquery :high_value_orders do
  query &__MODULE__.high_value_orders_subquery/1
  type :inner
  on [%{left: "id", right: "customer_id"}]
end
Link to this macro

defunnest(unnest_id, list)

(macro)

Defines a named UNNEST preset for Selecto.with_unnest/2.

example

Example

defunnest :product_tags do
  array_field "tags"
  as "tag"
  ordinality "tag_position"
end
Link to this macro

defvalues(values_id, list)

(macro)

Defines a named VALUES preset for Selecto.with_values/2.

example

Example

defvalues :status_lookup do
  rows [["active", "Active"], ["inactive", "Inactive"]]
  columns ["status", "label"]
  as "status_lookup"
  join [owner_key: :status, related_key: :status]
end
Link to this macro

dependencies(value)

(macro)

Sets CTE dependency names.

Link to this macro

description(value)

(macro)

Sets the filter description/help text.

Link to this macro

field(name, type, opts \\ [])

(macro)

Defines a field within a JSONB schema.

This macro is only valid inside a defjsonb_schema block.

examples

Examples

# Simple field with type and label
field :color, :string, label: "Color"

# Field with multiple options
field :weight, :decimal, label: "Weight", precision: 2, required: true

# Array field
field :tags, {:array, :string}, label: "Tags"

# Nested object field
field :dimensions, :object do
  field :width, :decimal
  field :height, :decimal
end
Link to this macro

filterable(value)

(macro)

Sets whether the column is filterable.

Link to this macro

format(value)

(macro)

Sets the display format for a column.

Common formats: :currency, :percentage, :number, :date, :datetime, :yes_no

Link to this macro

join(value)

(macro)

Sets join options for query member auto-join behavior.

Link to this macro

join_id(value)

(macro)

Sets explicit join id for named subquery members.

Link to this macro

join_type(value)

(macro)

Sets the join type for named LATERAL members.

Link to this macro

kind(value)

(macro)

Sets named subquery kind (:join currently supported).

Link to this macro

label(value)

(macro)

Sets the human-readable label for a column or filter.

Link to this macro

lateral_source(value)

(macro)

Alias for source/1 in named LATERAL members.

Link to this macro

max_length(value)

(macro)

Sets the maximum display length for string columns.

Link to this macro

name(value)

(macro)

Sets the human-readable name for a filter.

Link to this macro

on(value)

(macro)

Sets ON conditions for named subquery members.

Link to this macro

options(value)

(macro)

Sets the valid options for a select-type filter.

Link to this macro

ordinality(value)

(macro)

Sets ordinality alias for named UNNEST members.

Link to this macro

payload(value)

(macro)

Sets a payload map for a detail-row action.

Link to this macro

precision(value)

(macro)

Sets the numeric precision for decimal columns.

Link to this macro

query(value)

(macro)

Sets a query builder function for named query members.

Link to this macro

recursive_query(value)

(macro)

Sets recursive CTE recursive query function.

Link to this macro

required(value)

(macro)

Sets whether the filter is required.

Link to this macro

required_fields(value)

(macro)

Sets required fields for a detail-row action.

Link to this macro

returns(value)

(macro)

Sets the declared return type or return metadata for a UDF registration.

Link to this macro

rows(value)

(macro)

Sets VALUES rows for a named defvalues member.

Link to this macro

sortable(value)

(macro)

Sets whether the column is sortable.

Link to this macro

source(value)

(macro)

Sets a source expression for named LATERAL members.

Link to this macro

sql_name(value)

(macro)

Sets the SQL function name for a UDF registration.

Link to this macro

type(value)

(macro)

Sets the filter type.

Common types: :string, :integer, :boolean, :date, :datetime, :decimal