FatEcto v0.4.0 FatEcto.FatQuery.FatSelect View Source

Link to this section Summary

Functions

Build a select query depending on the params.

Link to this section Functions

Link to this function

build_select(queryable, select_params, model) View Source

Build a select query depending on the params.

Parameters

  • queryable- Schema name that represents your database model.
  • query_opts - include query options as a map

Examples

iex> query_opts = %{
...>  "$select" => %{
...>    "$fields" => ["name", "location", "rating"],
...>    "fat_rooms" => ["beds", "capacity"]
...>  },
...>  "$order" => %{"id" => "$desc"},
...>  "$where" => %{"rating" => 4},
...> "$include" => %{
...>    "fat_doctors" => %{
...>      "$include" => ["fat_patients"],
...>      "$where" => %{"name" => "ham"},
...>      "$order" => %{"id" => "$desc"}
...>    }
...>  }
...> }
iex> Elixir.FatEcto.FatQuery.build(FatEcto.FatHospital, query_opts)
#Ecto.Query<from f0 in FatEcto.FatHospital, join: f1 in assoc(f0, :fat_doctors), where: f0.rating == ^4 and ^true, order_by: [desc: f0.id], select: map(f0, [:name, :location, :rating, :id, {:fat_rooms, [:beds, :capacity]}]), preload: [fat_doctors: #Ecto.Query<from f in FatEcto.FatDoctor, where: f.name == ^"ham" and ^true, order_by: [desc: f.id], limit: ^10, offset: ^0, preload: [:fat_patients]>]>

Options

  • $include- Include the assoication doctors.
  • $include: :fat_patients- Include the assoication patients. Which has association with doctors.
  • $select- Select the fields from hospital and rooms.
  • $where- Added the where attribute in the query.
  • $order- Sort the result based on the order attribute.