AshSDUI.Query (ash_sdui v0.2.0)

Copy Markdown View Source

Generic query-state model used by views and bindings.

The struct captures the user-controlled parts of collection state in a runtime friendly way, while the query schema provides the allowed search, filter, and sort fields.

Summary

Functions

Builds a runtime query from params and a declared schema.

Merges query params into a path while preserving unrelated params.

Converts query state into Ash read options.

Serializes a runtime query back into URL params.

Updates a query from a named event and params.

Types

sort_direction()

@type sort_direction() :: :asc | :desc

sort_entry()

@type sort_entry() :: atom() | {atom(), sort_direction()}

t()

@type t() :: %AshSDUI.Query{
  default_limit: pos_integer() | nil,
  default_sort: sort_entry() | [sort_entry()] | nil,
  filter_fields: [atom()],
  filters: map(),
  limit: pos_integer() | nil,
  name: atom() | nil,
  offset: non_neg_integer() | nil,
  params: map(),
  search: String.t() | nil,
  search_fields: [atom()],
  sort: [sort_entry()],
  sort_fields: [atom()],
  source: term()
}

Functions

from_params(params, schema)

@spec from_params(map() | keyword() | nil, struct() | map() | nil) :: t() | nil

Builds a runtime query from params and a declared schema.

merge_path(path, query, current_params \\ %{})

@spec merge_path(String.t(), t() | nil, map() | nil) :: String.t()

Merges query params into a path while preserving unrelated params.

to_ash_opts(query, opts \\ [])

@spec to_ash_opts(
  t() | nil,
  keyword()
) :: keyword()

Converts query state into Ash read options.

to_params(query)

@spec to_params(t() | nil) :: map()

Serializes a runtime query back into URL params.

update(query, event, params)

@spec update(t() | nil, atom(), map() | keyword() | nil) :: t() | nil

Updates a query from a named event and params.