Selecto.Config.OverlayDSL (Selecto v0.3.16)
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, 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
endSupported types: :string, :integer, :decimal, :boolean, :date, :datetime,
{:array, type}, :object (with nested fields)
column-directives-within-defcolumn
Column Directives (within defcolumn)
label/1- Human-readable column labelformat/1- Display format (:currency,:percentage,:number,:date, etc.)aggregate_functions/1- List of allowed aggregations (:sum,:avg,:count,:min,:max)precision/1- Numeric precision for decimal typesmax_length/1- Maximum string length for displaysortable/1- Whether column can be sorted (boolean)filterable/1- Whether column can be filtered (boolean)
filter-directives-within-deffilter
Filter Directives (within deffilter)
name/1- Human-readable filter nametype/1- Filter type (:string,:integer,:boolean,:date, etc.)description/1- Help text for the filterrequired/1- Whether filter is required (boolean)default/1- Default value for the filteroptions/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 underdetail_actionsdefpopup id do ... end- Define a modal detail-row action underdetail_actions
query-member-macros
Query Member Macros
defcte id do ... end- Define a named CTE preset underquery_members.ctesdefvalues id do ... end- Define a named VALUES preset underquery_members.valuesdefsubquery id do ... end- Define a named subquery-join preset underquery_members.subqueriesdeflateral id do ... end- Define a named LATERAL preset underquery_members.lateralsdefunnest id do ... end- Define a named UNNEST preset underquery_members.unnests
domain-registry-macros
Domain Registry Macros
defjoin id, config- Define a top-level join entry underjoinsdefschema id, config- Define a top-level schema entry underschemasdefschema_assoc schema_id, assoc_id, config- Define a schemaassociationsentrydefsource_assoc id, config- Define a rootsource.associationsentry
query-member-directives
Query Member Directives
query/1- Query builder (fn -> selecto end,fn selecto -> selecto end, or capture)columns/1- Declared columns for CTE/VALUES presetsjoin/1- Auto-join options used by named member helpersrows/1- VALUES data rows (alias:data/1)source/1/lateral_source/1- LATERAL source tuple/queryarray_field/1- UNNEST source field/expressionjoin_type/1- LATERAL join type (:left,:inner, etc.)ordinality/1- UNNEST ordinality aliasas/1- VALUES alias namejoin_id/1- Subquery join id overrideon/1- Subquery join conditionsbase_query/1,recursive_query/1- Recursive CTE query functionsdependencies/1- CTE dependencieskind/1- Subquery preset kind (currently:join)
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 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 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 VALUES rows for a named defvalues member.
Sets whether the column is sortable.
Sets a source expression for named LATERAL members.
Sets the filter type.
Link to this section Functions
Sets the allowed aggregate functions for a column.
Options: :sum, :avg, :count, :min, :max
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.
example
Example
defcolumn :price do
label "Product Price"
format :currency
aggregate_functions [:sum, :avg]
end
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
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
Defines a custom filter.
example
Example
deffilter "price_range" do
name "Price Range"
type :string
description "Filter by price range"
end
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
}
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 (supportsprecisionoption):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 nestedfieldcalls)
field-options
Field Options
label- Human-readable label for displayprecision- Decimal precision (for:decimaltype)required- Whether the field is required (default: false)default- Default value for the fieldfilterable- Whether the field can be filtered (default: true)sortable- Whether the field can be sorted (default: true)format- Display format (:currency,:percentage, etc.)
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
Defines a modal detail-row action.
This is a convenience wrapper around defdetail_action that defaults type
to :modal.
Defines a schema configuration under the top-level schemas registry.
example
Example
defschema :initiative, %{
source_table: "initiatives",
columns: %{id: %{type: :integer}, name: %{type: :string}}
}
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
})
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
})
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
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
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
Sets CTE dependency names.
Sets the filter description/help text.
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
Sets whether the column is filterable.
Sets the display format for a column.
Common formats: :currency, :percentage, :number, :date, :datetime, :yes_no
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 VALUES rows for a named defvalues member.
Sets whether the column is sortable.
Sets a source expression for named LATERAL members.
Sets the filter type.
Common types: :string, :integer, :boolean, :date, :datetime, :decimal