Aurora.Uix.Integration.Ash.QueryParser (Aurora UIX v0.1.4-rc.6)

Copy Markdown

Parses and applies query options to Ash queries.

Transforms keyword list options into Ash query operations, supporting filtering, sorting, preloading, and other query modifications. Handles various comparison operators and automatically translates them to Ash-compatible formats.

Key Features

  • Supports :order_by for sorting
  • Handles :where clauses with multiple operators (:eq, :in, :between, :like, :ilike, :gte, :lte)
  • Supports :preload for loading associations
  • Automatically translates operation aliases (:ge, :le, :equal_to)
  • Comma-separated string parsing for :in operations

Key Constraints

  • Only processes :order_by, :where, and :preload options; other options are ignored
  • The :in operator expects either a list or comma-separated string
  • The :between operator requires start and end values

Summary

Functions

Parses and applies query options to an Ash query.

Functions

parse(query, opts \\ [])

@spec parse(
  Ash.Query.t(),
  keyword()
) :: Ash.Query.t()

Parses and applies query options to an Ash query.

Parameters

  • query (Ash.Query.t()) - The base Ash query to modify.
  • opts (keyword()) - Options:
    • :order_by (term()) - Sorting specification passed to Ash.Query.sort/2.
    • :where (list()) - List of filter clauses.
    • :preload (term()) - Associations to load.

Returns

Ash.Query.t() - The modified query with applied options.

Examples

iex> query = Ash.Query.new(MyApp.Post)
iex> parse(query, where: [{:status, :eq, "published"}], order_by: [inserted_at: :desc])
#Ash.Query<...>

iex> query = Ash.Query.new(MyApp.User)
iex> parse(query, where: [{:age, :between, 18, 65}])
#Ash.Query<...>

iex> query = Ash.Query.new(MyApp.Product)
iex> parse(query, where: [{:category, :in, "electronics,books"}])
#Ash.Query<...>