Tempo.Ecto.Tempo (Tempo SQL v0.4.0)

Copy Markdown View Source

Ecto.ParameterizedType for persisting a value as a PostgreSQL tstzrange: Tempo.Ecto.Interval under the name tempo_sql 0.2.0 gave a column of bare values, kept so that schemas written for it still compile.

A value is the span it names — ~o"2026Y" the whole of 2026, ~o"2026Y-06M" June 2026 — and is stored as that interval, as Tempo.Ecto.Interval stores it.

Usage

schema "years" do
  field :reporting_year, Tempo.Ecto.Tempo, resolution: :year
end

Options

  • :resolution — as for Tempo.Ecto.Interval. With :year, a year loads as the interval from that year through itself.

  • :frame — as for Tempo.Ecto.Interval: :utc (the default) for a tstzrange column, :floating for a tsrange column.

Round-trip caveat

A stored ~o"2026Y" loads back as the interval it names, not the value: a tstzrange keeps no more. Tempo.Ecto.TempoRange keeps the value as it was written.

Summary

Functions

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

Functions

cast_type(options \\ [])

@spec cast_type(keyword()) :: Ecto.Type.t()

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 writes the ends to the given unit on load. One of :year, :month, :day, :hour, :minute, or :second. Defaults to :second.

  • :frame is :utc (the default) for a tstzrange column or :floating for a tsrange column.

Returns

Examples

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

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