FatEcto v0.4.0 FatEcto.FatQuery.FatGroupBy View Source
Link to this section Summary
Functions
Build a group_by query
depending on the params.
Link to this section Functions
Link to this function
build_group_by(queryable, group_by_params) View Source
Build a group_by 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},
...> "$group" => "total_staff"
...> }
iex> Elixir.FatEcto.FatQuery.build(FatEcto.FatHospital, query_opts)
#Ecto.Query<from f in FatEcto.FatHospital, where: f.rating == ^4 and ^true, group_by: [f.total_staff], order_by: [desc: f.id], select: map(f, [:name, :location, :rating, :id, {:fat_rooms, [:beds, :capacity]}])>
Options
$select
- Select the fields fromhospital
androoms
.$where
- Added the where attribute in the query.$group
- Added the group_by attribute in the query.$order
- Sort the result based on the order attribute.