FatEcto v0.5.0 FatEcto.FatQuery.FatGroupBy View Source
Build a group_by
query according to the group_by field/fields passed in the params.
Parameters
queryable
- Ecto Queryable that represents your schema name, table name or query.query_opts
- Group_By query options as a map.
Examples
iex> query_opts = %{
...> "$select" => %{
...> "$fields" => ["name", "location", "rating"],
...> "fat_rooms" => ["name", "floor"]
...> },
...> "$order" => %{"id" => "$desc"},
...> "$where" => %{"rating" => 4},
...> "$group" => "total_staff"
...> }
iex> Elixir.MyApp.Query.build!(FatEcto.FatHospital, query_opts)
#Ecto.Query<from f0 in FatEcto.FatHospital, where: f0.rating == ^4 and ^true, group_by: [f0.total_staff], order_by: [desc: f0.id], select: map(f0, [:name, :location, :rating, {:fat_rooms, [:name, :floor]}])>
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.
Parameters
queryable
- Ecto Queryable that represents your schema name, table name or query.query_opts
- Group_By query options as a map.
Examples
iex> query_opts = %{
...> "$select" => %{
...> "$fields" => ["name", "location", "rating"],
...> "fat_rooms" => ["name", "floor"]
...> },
...> "$order" => %{"id" => "$desc"},
...> "$where" => %{"rating" => 4},
...> "$group" => ["total_staff", "rating"]
...> }
iex> Elixir.MyApp.Query.build!(FatEcto.FatHospital, query_opts)
#Ecto.Query<from f0 in FatEcto.FatHospital, where: f0.rating == ^4 and ^true, group_by: [f0.total_staff], group_by: [f0.rating], order_by: [desc: f0.id], select: map(f0, [:name, :location, :rating, {:fat_rooms, [:name, :floor]}])>
Options
$select
- Select the fields fromhospital
androoms
.$where
- Added the where attribute in the query.$group
- Added the group_by attributes in the query.$order
- Sort the result based on the order attribute.
Link to this section Summary
Functions
Builds a group_by
query.
Link to this section Functions
Link to this function
build_group_by(queryable, group_params, build_options, opts \\ [])
View Source Builds a group_by
query.
Parameters
queryable
- Ecto Queryable that represents your schema name, table name or query.query_opts
- Group_By query options as a map.opts
- Pass options related to query bindings.build_options
- Pass options related to otp_app.
Examples
iex> query_opts = %{
...> "$select" => %{
...> "$fields" => ["name", "location", "rating"],
...> "fat_rooms" => ["name", "floor"]
...> },
...> "$order" => %{"id" => "$desc"},
...> "$where" => %{"rating" => 4},
...> "$group" => ["total_staff", "rating"]
...> }
iex> Elixir.FatEcto.FatQuery.FatGroupBy.build_group_by(FatEcto.FatHospital, query_opts["$group"], [], [])
#Ecto.Query<from f0 in FatEcto.FatHospital, group_by: [f0.total_staff], group_by: [f0.rating]>