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
endOptions
:resolution— as forTempo.Ecto.Interval. With:year, a year loads as the interval from that year through itself.:frame— as forTempo.Ecto.Interval::utc(the default) for atstzrangecolumn,:floatingfor atsrangecolumn.
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
@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
optionsis a keyword list of options.
Options
:resolutionwrites the ends to the given unit on load. One of:year,:month,:day,:hour,:minute, or:second. Defaults to:second.:frameis:utc(the default) for atstzrangecolumn or:floatingfor atsrangecolumn.
Returns
- A
Ecto.ParameterizedType.opts/0tuple.
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}}}