View Source FatEcto.FatQuery.FatDynamics (FatEcto v1.0.0)

Builds a where query using dynamics.

Parameters

  • queryable - Ecto Queryable that represents your schema name, table name or query.
  • query_opts - Where query options as a map.

Examples

iex> query_opts = %{
...>    "$select" => %{
...>     "$fields" => ["name", "location", "rating"]
...>    },
...>   "$where" => %{
...>      "name" => "%John%",
...>      "location" => nil,
...>      "rating" => "$not_null",
...>      "total_staff" => %{"$between" => [1, 3]}
...>    }
...>  }
iex> Elixir.MyApp.Query.build!(FatEcto.FatHospital, query_opts)
#Ecto.Query<from f0 in FatEcto.FatHospital, where: f0.total_staff > ^1 and f0.total_staff < ^3 and

(not is_nil(f0.rating) and (f0.name == ^"%John%" and (is_nil(f0.location) and ^true))), select: map(f0, [:name, :location, :rating])>

Options

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

Summary

Functions

Builds a dynamic query where value is between the provided attributes.

Builds a dynamic query where value is equal and between the provided attributes.

Builds a dynamic query when value of jsonb matches with any list attribute.

Builds a dynamic query when value of jsonb field is in the list.

Builds a dynamic query where field is equal to value.

Builds a dynamic query where field is greater than the value.

Builds a dynamic query where field is greater than and equal to given value.

Builds a dynamic query where field matches the value substring.

Builds a dynamic query where value is in the provided list attributes.

Builds a dynamic query where field matches matches the value substring.

Builds a dynamic query where field is less than the value.

Builds a dynamic query where field is less than and equal to the value.

Builds a dynamic query where field is nil.

Functions

array_ilike_dynamic(key, value, dynamics, opts \\ [])

@spec array_ilike_dynamic(any(), any(), any(), nil | maybe_improper_list() | map()) ::
  %Ecto.Query.DynamicExpr{
    binding: term(),
    file: term(),
    fun: term(),
    line: term()
  }

between_dynamic(key, values, dynamics, opts \\ [])

@spec between_dynamic(any(), any(), any(), nil | keyword() | map()) ::
  %Ecto.Query.DynamicExpr{
    binding: term(),
    file: term(),
    fun: term(),
    line: term()
  }

Builds a dynamic query where value is between the provided attributes.

Parameters

  • key - Field name.
  • value - Values of the field as a list.
  • dynamics - Default or previous dynamic to append to the query.
  • opts - Options related to query bindings alongwith dynamic type(and/or).

Examples

iex> result = Elixir.FatEcto.FatQuery.FatDynamics.between_dynamic("experience_years", [2, 5], true, [dynamic_type: :and])
iex> inspect(result)
"dynamic([q], q.experience_years > ^2 and q.experience_years < ^5 and ^true)"

between_equal_dynamic(key, values, dynamics, opts \\ [])

@spec between_equal_dynamic(any(), any(), any(), nil | keyword() | map()) ::
  %Ecto.Query.DynamicExpr{
    binding: term(),
    file: term(),
    fun: term(),
    line: term()
  }

Builds a dynamic query where value is equal and between the provided attributes.

Parameters

  • key - Field name.
  • value - Values of the field as a list.
  • dynamics - Default or previous dynamic to append to the query.
  • opts - Options related to query bindings alongwith dynamic type(and/or).

Examples

iex> result = Elixir.FatEcto.FatQuery.FatDynamics.between_equal_dynamic("experience_years", [2, 5], true, [dynamic_type: :and])
iex> inspect(result)
"dynamic([q], q.experience_years >= ^2 and q.experience_years <= ^5 and ^true)"

contains_any_dynamic(key, values, dynamics, opts \\ [])

@spec contains_any_dynamic(any(), any(), any(), nil | keyword() | map()) ::
  %Ecto.Query.DynamicExpr{
    binding: term(),
    file: term(),
    fun: term(),
    line: term()
  }

Builds a dynamic query when value of jsonb matches with any list attribute.

Parameters

  • key - Field name.
  • values - values of jsonb field.
  • dynamics - Default or previous dynamic to append to the query.
  • opts - Options related to query bindings alongwith dynamic type(and/or).

contains_dynamic(key, values, dynamics, opts \\ [])

@spec contains_dynamic(any(), any(), any(), nil | keyword() | map()) ::
  %Ecto.Query.DynamicExpr{
    binding: term(),
    file: term(),
    fun: term(),
    line: term()
  }

Builds a dynamic query when value of jsonb field is in the list.

Parameters

  • key - Field name.
  • values - values of jsonb field.
  • dynamics - Default or previous dynamic to append to the query.
  • opts - Options related to query bindings alongwith dynamic type(and/or).

eq_dynamic(key, value, dynamics, opts \\ [])

@spec eq_dynamic(any(), any(), any(), nil | keyword() | map()) ::
  %Ecto.Query.DynamicExpr{
    binding: term(),
    file: term(),
    fun: term(),
    line: term()
  }

Builds a dynamic query where field is equal to value.

Parameters

  • key - Field name.
  • value - Value of the field.
  • dynamics - Default or previous dynamic to append to the query.
  • opts - Options related to query bindings alongwith dynamic type(and/or).

Examples

 iex> result = Elixir.FatEcto.FatQuery.FatDynamics.eq_dynamic("experience_years", 2, true, [dynamic_type: :and])
 iex> inspect(result)
 "dynamic([q], q.experience_years == ^2 and ^true)"

gt_dynamic(key, value, dynamics, opts \\ [])

@spec gt_dynamic(any(), any(), any(), nil | keyword() | map()) ::
  %Ecto.Query.DynamicExpr{
    binding: term(),
    file: term(),
    fun: term(),
    line: term()
  }

Builds a dynamic query where field is greater than the value.

Parameters

  • key - Field name.
  • value - Value of the field.
  • dynamics - Default or previous dynamic to append to the query.
  • opts - Options related to query bindings alongwith dynamic type(and/or).

Examples

iex> result = Elixir.FatEcto.FatQuery.FatDynamics.gt_dynamic("experience_years", 2, true, [dynamic_type: :or, binding: :last])
iex> inspect(result)
"dynamic([_, _, c], c.experience_years > ^2 or ^true)"

gte_dynamic(key, value, dynamics, opts \\ [])

@spec gte_dynamic(any(), any(), any(), nil | keyword() | map()) ::
  %Ecto.Query.DynamicExpr{
    binding: term(),
    file: term(),
    fun: term(),
    line: term()
  }

Builds a dynamic query where field is greater than and equal to given value.

Parameters

  • key - Field name.
  • value - Value of the field.
  • dynamics - Default or previous dynamic to append to the query.
  • opts - Options related to query bindings alongwith dynamic type(and/or).

Examples

iex> result = Elixir.FatEcto.FatQuery.FatDynamics.gte_dynamic("experience_years", 2, true, [dynamic_type: :and, binding: :last])
iex> inspect(result)
"dynamic([_, _, c], c.experience_years >= ^2 and ^true)"

ilike_dynamic(key, value, dynamics, opts \\ [])

@spec ilike_dynamic(any(), any(), any(), nil | keyword() | map()) ::
  %Ecto.Query.DynamicExpr{
    binding: term(),
    file: term(),
    fun: term(),
    line: term()
  }

Builds a dynamic query where field matches the value substring.

Parameters

  • key - Field name.
  • value - Value of the field.
  • dynamics - Default or previous dynamic to append to the query.
  • opts - Options related to query bindings alongwith dynamic type(and/or).

in_dynamic(key, values, dynamics, opts \\ [])

@spec in_dynamic(any(), any(), any(), nil | keyword() | map()) ::
  %Ecto.Query.DynamicExpr{
    binding: term(),
    file: term(),
    fun: term(),
    line: term()
  }

Builds a dynamic query where value is in the provided list attributes.

Parameters

  • key - Field name.
  • values - Pass a list of values of the field that represent range.
  • dynamics - Default or previous dynamic to append to the query.
  • opts - Options related to query bindings alongwith dynamic type(and/or).

Examples

iex> result = Elixir.FatEcto.FatQuery.FatDynamics.in_dynamic("experience_years", [2, 5], true, [dynamic_type: :and])
iex> inspect(result)
"dynamic([q], q.experience_years in ^[2, 5] and ^true)"

like_dynamic(key, value, dynamics, opts \\ [])

@spec like_dynamic(any(), any(), any(), nil | keyword() | map()) ::
  %Ecto.Query.DynamicExpr{
    binding: term(),
    file: term(),
    fun: term(),
    line: term()
  }

Builds a dynamic query where field matches matches the value substring.

Parameters

  • key - Field name.
  • value - Value of the field.
  • dynamics - Default or previous dynamic to append to the query.
  • opts - Options related to query bindings alongwith dynamic type(and/or).

lt_dynamic(key, value, dynamics, opts \\ [])

@spec lt_dynamic(any(), any(), any(), nil | keyword() | map()) ::
  %Ecto.Query.DynamicExpr{
    binding: term(),
    file: term(),
    fun: term(),
    line: term()
  }

Builds a dynamic query where field is less than the value.

Parameters

  • key - Field name.
  • value - Value of the field.
  • dynamics - Default or previous dynamic to append to the query.
  • opts - Options related to query bindings alongwith dynamic type(and/or).

Examples

iex> result = Elixir.FatEcto.FatQuery.FatDynamics.lt_dynamic("experience_years", 2, true, [dynamic_type: :and, binding: :last])
iex> inspect(result)
"dynamic([_, _, c], c.experience_years < ^2 and ^true)"

lte_dynamic(key, value, dynamics, opts \\ [])

@spec lte_dynamic(any(), any(), any(), nil | keyword() | map()) ::
  %Ecto.Query.DynamicExpr{
    binding: term(),
    file: term(),
    fun: term(),
    line: term()
  }

Builds a dynamic query where field is less than and equal to the value.

Parameters

  • key - Field name.
  • value - Value of the field.
  • dynamics - Default or previous dynamic to append to the query.
  • opts - Options related to query bindings alongwith dynamic type(and/or).

Examples

iex> result = Elixir.FatEcto.FatQuery.FatDynamics.lte_dynamic("experience_years", 2, true, [dynamic_type: :or])
iex> inspect(result)
"dynamic([q], q.experience_years <= ^2 or ^true)"

nil_dynamic?(key, dynamics, opts \\ [])

@spec nil_dynamic?(any(), any(), nil | keyword() | map()) :: %Ecto.Query.DynamicExpr{
  binding: term(),
  file: term(),
  fun: term(),
  line: term()
}

Builds a dynamic query where field is nil.

Parameters

  • key - Field name .
  • dynamics - Default or previous dynamic to append to the query.
  • opts - Options related to query bindings alongwith dynamic type(and/or).

Examples

iex> result = Elixir.FatEcto.FatQuery.FatDynamics.nil_dynamic?("location", true, [dynamic_type: :and])
iex> inspect(result)
"dynamic([c], is_nil(c.location) and ^true)"

not_eq_dynamic(key, value, dynamics, opts \\ [])

@spec not_eq_dynamic(any(), any(), any(), nil | keyword() | map()) ::
  %Ecto.Query.DynamicExpr{
    binding: term(),
    file: term(),
    fun: term(),
    line: term()
  }