View Source EctoRange.Num (ecto_range v0.2.1)

A Postgres range of numeric values. Equivalent to numrange. Allows numeric values of all precisions. Returns Decimal structs when loading from the database.

Watch out: Not defining the precision of your values, might cause compatibility problems with other systems in the future.

Link to this section Summary

Functions

Callback implementation for Ecto.Type.embed_as/1.

Callback implementation for Ecto.Type.equal?/2.

Converts a Postgrex.Range.t() into a normalized form. For bounded ranges, it will make the lower and upper bounds inclusive.

Checks and converts a Postgrex.Range or tuple into a Postgrex.Range.t()

Link to this section Functions

Callback implementation for Ecto.Type.embed_as/1.

Callback implementation for Ecto.Type.equal?/2.

Converts a Postgrex.Range.t() into a normalized form. For bounded ranges, it will make the lower and upper bounds inclusive.

All upper and lower bounds are converted to %Decimal{} structs, if necessary.

examples

Examples

iex> range = %Postgrex.Range{lower: 1, upper: 3, lower_inclusive: true, upper_inclusive: false}
iex> EctoRange.Num.normalize_range(range)
%Postgrex.Range{lower: %Decimal{coef: 1}, upper: %Decimal{coef: 2999999999, exp: -9}, lower_inclusive: true, upper_inclusive: true}

iex> range = %Postgrex.Range{lower: 1, upper: 3, lower_inclusive: false, upper_inclusive: true}
iex> EctoRange.Num.normalize_range(range)
%Postgrex.Range{lower: %Decimal{coef: 1000000001, exp: -9}, upper: %Decimal{coef: 3}, lower_inclusive: true, upper_inclusive: true}
Link to this function

to_postgrex_range(range)

View Source
@spec to_postgrex_range(
  Postgrex.Range.t()
  | {number(), number()}
  | {Decimal.t(), Decimal.t()}
) ::
  Postgrex.Range.t()

Checks and converts a Postgrex.Range or tuple into a Postgrex.Range.t()

examples

Examples

iex> EctoRange.Date.to_postgrex_range({1, 3})
%Postgrex.Range{lower: 1, upper: 3, lower_inclusive: true, upper_inclusive: true}