FatEcto v0.1.5 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.

=> notLike

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" => %{"location" => %{"$not_like" => "%street2 %"}},
...>  "$order" => %{"id" => "$desc"}
...> }
iex> Elixir.FatEcto.FatQuery.build(FatEcto.FatHospital, query_opts)
#Ecto.Query<from f in FatEcto.FatHospital, where: not(like(fragment("(?)::TEXT", f.location), ^"%street2 %")) and ^true, order_by: [desc: f.id], select: map(f, [:name, :location, :rating, :id, {:fat_rooms, [:beds, :capacity]}])>

Options

  • $select- Select the fields from hospital and rooms.
  • $not_like- Added the notlike attribute in the where query.
  • $order- Sort the result based on the order attribute.

=> notILike

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"]
...>   },
...>  "$where" => %{"location" => %{"$not_ilike" => "%street2 %"}},
...>  "$group" => "rating"
...> }
iex> Elixir.FatEcto.FatQuery.build(FatEcto.FatHospital, query_opts)
#Ecto.Query<from f in FatEcto.FatHospital, where: not(ilike(fragment("(?)::TEXT", f.location), ^"%street2 %")) and ^true, group_by: [f.rating], select: map(f, [:name, :location, :rating])>

Options

  • $select- Select the fields from hospital and rooms.
  • $not_ilike- Added the notilike attribute in the where query.
  • $group- Added the group_by attribute in the query.

=> lessThan

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"]
...>    },
...>   "$where" => %{"rating" => %{"$lt" => 4}}
...>  }
iex> Elixir.FatEcto.FatQuery.build(FatEcto.FatHospital, query_opts)
#Ecto.Query<from f in FatEcto.FatHospital, where: f.rating < ^4 and ^true, select: map(f, [:name, :location, :rating])>

Options

  • $select- Select the fields from hospital.
  • $lt- Added the lessthan attribute in the where query.

=> lessThan the other field

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"]
...>    },
...>    "$where" => %{"total_staff" => %{"$lt" => "$rating"}},
...>    "$order" => %{"id" => "$desc"}
...>  }
iex> Elixir.FatEcto.FatQuery.build(FatEcto.FatHospital, query_opts)
#Ecto.Query<from f in FatEcto.FatHospital, where: f.total_staff < f.rating and ^true, order_by: [desc: f.id], select: map(f, [:name, :location, :rating])>

Options

  • $select- Select the fields from hospital.
  • $lt: :$field- Added the lessthan attribute in the where query.
  • $order- Sort the result based on the order attribute.

=> lessThanEqual

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" => %{"total_staff" => %{"$lte" => 3}},
...>  }
iex> Elixir.FatEcto.FatQuery.build(FatEcto.FatHospital, query_opts)
#Ecto.Query<from f in FatEcto.FatHospital, where: f.total_staff <= ^3 and ^true, select: map(f, [:name, :location, :rating, :id, {:fat_rooms, [:beds, :capacity]}])>

Options

  • $select- Select the fields from hospital and rooms.
  • $lte- Added the lessthanequal attribute in the where query.

=> lessThanEqual the other field

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" => %{"total_staff" => %{"$lte" => "$rating"}},
...>  "$group" => "total_staff"
...> }
iex> Elixir.FatEcto.FatQuery.build(FatEcto.FatHospital, query_opts)
#Ecto.Query<from f in FatEcto.FatHospital, where: f.total_staff <= f.rating and ^true, group_by: [f.total_staff], select: map(f, [:name, :location, :rating, :id, {:fat_rooms, [:beds, :capacity]}])>

Options

  • $select- Select the fields from hospital and rooms.
  • $lte: :$field- Added the lessthanequal attribute in the where query.
  • $group- Added the group_by attribute in the query.

=> greaterThan

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" => %{"total_staff" => %{"$gt" => 4}},
...>  "$group" => "total_staff",
...>  "$order" => %{"rating" => "$desc"}
...> }
iex> Elixir.FatEcto.FatQuery.build(FatEcto.FatHospital, query_opts)
#Ecto.Query<from f in FatEcto.FatHospital, where: f.total_staff > ^4 and ^true, group_by: [f.total_staff], order_by: [desc: f.rating], select: map(f, [:name, :location, :rating, :id, {:fat_rooms, [:beds, :capacity]}])>

Options

  • $select- Select the fields from hospital and rooms.
  • $gt- Added the lessthan attribute in the where query.
  • $group- Added the group_by attribute in the query.
  • $order- Sort the result based on the order attribute.

=> greaterThan the other field

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" => %{"total_staff" => %{"$gt" => "$rating"}},
...>  "$include" => %{
...>    "fat_doctors" => %{
...>      "$where" => %{"rating" => %{"$lt" => 3}},          
...>      "$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.total_staff > f0.rating and ^true, select: map(f0, [:name, :location, :rating, :id, {:fat_rooms, [:beds, :capacity]}]), preload: [fat_doctors: #Ecto.Query<from f in FatEcto.FatDoctor, where: f.rating < ^3 and ^true, order_by: [desc: f.id], limit: ^10, offset: ^0>]>

Options

  • $select- Select the fields from hospital.
  • $gt: :$field- Added the greaterthan attribute in the where query.
  • $include- Include the assoication model doctors.
  • $lt- Added the lessthan attribute in the where query inside include.

=> greaterThanEqual

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" => %{"total_staff" => %{"$gte" => 5}},
...>  "$include" => %{
...>   "fat_doctors" => %{
...>    "$where" => %{"rating" => %{"$lte" => 3}},          
...>   }
...>  }   
...> }
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.total_staff >= ^5 and ^true, select: map(f0, [:name, :location, :rating, :id, {:fat_rooms, [:beds, :capacity]}]), preload: [fat_doctors: #Ecto.Query<from f in FatEcto.FatDoctor, where: f.rating <= ^3 and ^true, limit: ^10, offset: ^0>]>

Options

  • $select- Select the fields from hospital and rooms.
  • $gte- Added the greaterthanequal attribute in the where query.
  • $include- Include the assoication model doctors.
  • $lte- Added the lessthanequal attribute in the where query inside include.

=> greaterThanEqual the other field

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" => %{"rating" => %{"$gte" => "$total_staff"}},
...>  "$include" => %{
...>    "fat_doctors" => %{
...>      "$where" => %{"rating" => %{"$gte" => 3}},
...>      "$order" => %{"total_staff" => "$asc"}          
...>     }
...>   }   
...> }
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 >= f0.total_staff and ^true, select: map(f0, [:name, :location, :rating, :id, {:fat_rooms, [:beds, :capacity]}]), preload: [fat_doctors: #Ecto.Query<from f in FatEcto.FatDoctor, where: f.rating >= ^3 and ^true, order_by: [asc: f.total_staff], limit: ^10, offset: ^0>]>

Options

  • $select- Select the fields from hospital and rooms.
  • $gte: :$field- Added the greaterthanequal attribute in the where query.
  • $include- Include the assoication model doctors.
  • $gte- Added the greaterthanequal attribute in the where query inside include.
  • $order- Sort the result based on the order attribute.

=> between

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" => %{"rating" => %{"$between" => [10, 20]}},
...>  "$include" => %{
...>    "fat_doctors" => %{
...>     "$include" => ["fat_patients"],
...>     "$where" => %{"rating" => %{"$gte" => "$total_staff"}},
...>     "$order" => %{"total_staff" => "$asc"}          
...>    }
...>   }   
...> }
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 > ^10 and f0.rating < ^20 and ^true, select: map(f0, [:name, :location, :rating, :id, {:fat_rooms, [:beds, :capacity]}]), preload: [fat_doctors: #Ecto.Query<from f0 in FatEcto.FatDoctor, left_join: f1 in assoc(f0, :fat_patients), where: f0.rating >= f0.total_staff and ^true, order_by: [asc: f0.total_staff], limit: ^10, offset: ^0, preload: [:fat_patients]>]>

Options

  • $select- Select the fields from hospital and rooms.
  • $between: :$field- Added the between attribute in the where query.
  • $include- Include the assoication model doctors and patients.
  • $gte- Added the greaterthanequal attribute in the where query inside include.
  • $order- Sort the result based on the order attribute.