View Source FatEcto.FatQuery.FatOrderBy (FatEcto v1.0.0)

Builds query with asc or desc order.

This module provides functionality to dynamically add order_by clauses to Ecto queries based on the provided parameters. It supports various order formats, including $asc, $desc, and nulls handling ($asc_nulls_first, $desc_nulls_last, etc.).

Summary

Functions

Orders the results based on the order_by clause in the params.

Functions

build_order_by(queryable, order_by_params, build_options, opts \\ [])

@spec build_order_by(any(), any(), any(), any()) :: any()

Orders the results based on the order_by clause in the params.

Parameters

  • queryable: Ecto Queryable that represents your schema name, table name, or query.
  • order_by_params: A map of fields and their order formats (e.g., %{"field" => "$asc"}).
  • opts: Options related to query bindings.
  • build_options: Options related to the OTP app (unused in this function).

Examples

iex> query_opts = %{"$order" => %{"id" => "$asc"}}
iex> FatEcto.FatQuery.FatOrderBy.build_order_by(FatEcto.FatHospital, query_opts["$order"], [], [])
#Ecto.Query<from f0 in FatEcto.FatHospital, order_by: [asc: f0.id]>