FatEcto v0.1.2 FatEcto.FatQuery.FatWhere View Source

Where supports multiple query methods.

like

Parameters

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

Example

iex> query_opts = %{
...>   "$select" => %{"$fields" => ["name", "designation", "experience_years"]},
...>   "$where" => %{"name" => %{"$like" => "%Joh %"}}
...> }
iex> Elixir.FatEcto.FatQuery.build(FatEcto.FatDoctor, query_opts)
#Ecto.Query<from f in FatEcto.FatDoctor, where: like(fragment("(?)::TEXT", f.name), ^"%Joh %") and ^true, select: map(f, [:name, :designation, :experience_years])>

Options

  • $select- Select the fields from doctor.
  • $like- Added the like attribute in the where query.

iLike

Parameters

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

Example

iex> query_opts = %{
...>   "$select" => %{"$fields" => ["name", "designation", "experience_years"]},
...>   "$where" => %{"designation" => %{"$ilike" => "%surge %"}},
...>   "$order" => %{"rating" => "$asc"}
...> }
iex> Elixir.FatEcto.FatQuery.build(FatEcto.FatDoctor, query_opts)
#Ecto.Query<from f in FatEcto.FatDoctor, where: ilike(fragment("(?)::TEXT", f.designation), ^"%surge %") and ^true, order_by: [asc: f.rating], select: map(f, [:name, :designation, :experience_years])>

Options

  • $select- Select the fields from doctor.
  • $ilike- Added the ilike attribute in the where query.
  • $order- Sort the result based on the order attribute.