FatEcto v0.3.3 FatEcto.FatQuery.FatOrderBy View Source
Order supports asc
and desc
query methods.
=> $asc
Parameters
queryable
- Schema name that represents your database model.query_opts
- include query options as a map.
Example
iex> query_opts = %{
...> "$select" => %{
...> "$fields" => ["name", "location", "rating"],
...> "fat_rooms" => ["beds", "capacity"]
...> },
...> "$where" => %{"name" => "saint claire"},
...> "$group" => ["rating", "total_staff"],
...> "$order" => %{"total_staff" => "$asc"},
...> "$include" => %{
...> "fat_doctors" => %{
...> "$include" => ["fat_patients"],
...> "$where" => %{"rating" => %{"$gt" => 5}},
...> "$order" => %{"experience_years" => "$asc"},
...> "$select" => ["name", "designation", "phone"]
...> }
...> },
...> "$right_join" => %{
...> "fat_rooms" => %{
...> "$on_field" => "id",
...> "$on_join_table_field" => "hospital_id",
...> "$select" => ["beds", "capacity", "level"],
...> "$where" => %{"beds" => 10},
...> "$order" => %{"nurses" => "$asc"}
...> }
...> }
...> }
iex> Elixir.FatEcto.FatQuery.build(FatEcto.FatHospital, query_opts)
#Ecto.Query<from f0 in FatEcto.FatHospital, right_join: f1 in "fat_rooms", on: f0.id == f1.hospital_id, join: f2 in assoc(f0, :fat_doctors), where: f0.name == ^"saint claire" and ^true, where: f1.beds == ^10 and ^true, group_by: [f0.rating], group_by: [f0.total_staff], order_by: [asc: f1.nurses], order_by: [asc: f0.total_staff], select: merge(map(f0, [:name, :location, :rating, :id, {:fat_rooms, [:beds, :capacity]}]), %{^:fat_rooms => map(f1, [:beds, :capacity, :level])}), preload: [fat_doctors: #Ecto.Query<from f in FatEcto.FatDoctor, where: f.rating > ^5 and ^true, order_by: [asc: f.experience_years], limit: ^10, offset: ^0, select: map(f, [:name, :designation, :phone]), preload: [:fat_patients]>]>
Options
$select
- Select the fields fromhospital
androoms
.$right_join: :$select
- Select the fields fromrooms
.$include: :$select
- Select the fields fromdoctors
.$right_join
- Right join the tablerooms
.$include
- Include the assoication modeldoctors
andpatients
.$gt
- Added the greaterthan attribute in the where query inside include .$order
- Sort the result based on the order attribute.$right_join: :$order
- Sort the result based on the order attribute inside join.$include: :$order
- Sort the result based on the order attribute inside include.$group
- Added the group_by attribute in the query.
=> $desc
Parameters
queryable
- Schema name that represents your database model.query_opts
- include query options as a map.
Example
iex> query_opts = %{
...> "$select" => %{
...> "$fields" => ["name", "location", "rating"],
...> "fat_rooms" => ["beds", "capacity"]
...> },
...> "$where" => %{"name" => "saint claire"},
...> "$group" => ["rating", "total_staff"],
...> "$order" => %{"rating" => "$desc"},
...> "$include" => %{
...> "fat_doctors" => %{
...> "$include" => ["fat_patients"],
...> "$where" => %{"rating" => %{"$gt" => 5}},
...> "$order" => %{"experience_years" => "$asc"},
...> "$select" => ["name", "designation", "phone"]
...> }
...> },
...> "$right_join" => %{
...> "fat_rooms" => %{
...> "$on_field" => "id",
...> "$on_join_table_field" => "hospital_id",
...> "$select" => ["beds", "capacity", "level"],
...> "$where" => %{"beds" => 10},
...> "$order" => %{"capacity" => "$desc"}
...> }
...> }
...> }
iex> Elixir.FatEcto.FatQuery.build(FatEcto.FatHospital, query_opts)
#Ecto.Query<from f0 in FatEcto.FatHospital, right_join: f1 in "fat_rooms", on: f0.id == f1.hospital_id, join: f2 in assoc(f0, :fat_doctors), where: f0.name == ^"saint claire" and ^true, where: f1.beds == ^10 and ^true, group_by: [f0.rating], group_by: [f0.total_staff], order_by: [desc: f1.capacity], order_by: [desc: f0.rating], select: merge(map(f0, [:name, :location, :rating, :id, {:fat_rooms, [:beds, :capacity]}]), %{^:fat_rooms => map(f1, [:beds, :capacity, :level])}), preload: [fat_doctors: #Ecto.Query<from f in FatEcto.FatDoctor, where: f.rating > ^5 and ^true, order_by: [asc: f.experience_years], limit: ^10, offset: ^0, select: map(f, [:name, :designation, :phone]), preload: [:fat_patients]>]>
Options
$select
- Select the fields fromhospital
androoms
.$right_join: :$select
- Select the fields fromrooms
.$include: :$select
- Select the fields fromdoctors
.$right_join
- Right join the tablerooms
.$include
- Include the assoication modeldoctors
andpatients
.$gt
- Added the greaterthan attribute in the where query inside include .$order
- Sort the result based on the order attribute.$right_join: :$order
- Sort the result based on the order attribute inside join.$include: :$order
- Sort the result based on the order attribute inside include.$group
- Added the group_by attribute in the query.