Tempo.Ecto.IntervalSet (Tempo SQL v0.2.0)

Copy Markdown View Source

Ecto.ParameterizedType for persisting a Tempo.IntervalSet.t/0 as a PostgreSQL tstzmultirange value (PostgreSQL 14+).

Usage

schema "alice_calendar" do
  field :busy_times, Tempo.Ecto.IntervalSet
end

and in the migration:

add :busy_times, :tstzmultirange

(or use Tempo.SQL.Migration.add_interval_set/2).

Options

  • :resolution — on load, truncate every member interval's endpoints to the given component. Same values and semantics as Tempo.Ecto.Interval.

Storage contract

Every member interval must satisfy the same contract as Tempo.Ecto.Interval. In addition:

  • The set must be non-empty. An empty multirange round-trips as '{}'::tstzmultirange; use a NULL column to represent "no set".

  • Every member must be bounded on both ends (Tempo's IntervalSet.new/2 already enforces this).

Summary

Functions

Builds the parameterized-type tuple for use outside a schema.

Functions

cast_type(options \\ [])

Builds the parameterized-type tuple for use outside a schema.

See Tempo.Ecto.Interval.cast_type/1 for the schema-side equivalent and the full discussion.

Arguments

  • options is a keyword list of options.

Options

  • :resolution truncates member interval's endpoints on load to the given component. One of :year, :month, :day, :hour, :minute, or :second. Defaults to :second.

Returns

Examples

iex> Tempo.Ecto.IntervalSet.cast_type()
{:parameterized, {Tempo.Ecto.IntervalSet, %{resolution: :second}}}

iex> Tempo.Ecto.IntervalSet.cast_type(resolution: :day)
{:parameterized, {Tempo.Ecto.IntervalSet, %{resolution: :day}}}