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

Copy Markdown View Source

Ecto.ParameterizedType that stores a Tempo expression whole in a SQLite TEXT column.

SQLite has no range type. The column holds the JSON document Tempo.SQL.SQLite.Document writes: the expression's ISO 8601 text, read back as it was written, beside the integer bounds of the time it covers and of each of its spans, which Tempo.Ecto.SQLite.QueryAPI queries. It takes any expression with ISO 8601 text and a place on the time line: a value, an interval, a set, a recurrence.

Usage

schema "meetings" do
  field :window, Tempo.Ecto.SQLite.TempoRange
  field :opening_hours, Tempo.Ecto.SQLite.TempoRange, frame: :floating
end

and in the migration:

import Tempo.SQL.SQLite.Migration

create table(:meetings) do
  add_tempo_range :window
end

create_tempo_range_index :meetings, :window

Options

  • :frame — :utc (the default) for values in a zone or at a time shift, stored as seconds since the Unix epoch at UTC, or :floating for values with neither, stored as seconds on the wall clock. A value of the other frame is refused by cast/2, as a changeset error that names the frame to declare, and by dump/3.

Precision

The bounds are whole seconds, rounded outward, so a query of a span shorter than a second may find its neighbours. The expression itself is kept as written and loads back exactly.

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.

Arguments

  • options is a keyword list of options.

Options

  • :frame is :utc (the default) or :floating.

Returns

Examples

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

iex> Tempo.Ecto.SQLite.TempoRange.cast_type(frame: :floating)
{:parameterized, {Tempo.Ecto.SQLite.TempoRange, %{frame: :floating}}}