FatEcto v0.5.0 FatEcto.FatQuery.FatSelect View Source
Builds a select
query based on the params passed.
Parameters
queryable
- Ecto Queryable that represents your schema name, table name or query.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 assoicationdoctors
.$include: :fat_patients
- Include the assoicationpatients
. Which has association withdoctors
.$select
- Select the fields fromhospital
androoms
.$where
- Added the where attribute in the query.$order
- Sort the result based on the order attribute.