# Tempo SQL v0.3.0 - Table of Contents

> Ecto types, query macros and migration helpers that store Tempo expressions in PostgreSQL ranges and multiranges.

## Pages

- [Tempo SQL](readme.md)
- [Storage contract](storage-contract.md)
- [Changelog](changelog.md)
- [License](license.md)

## Modules

- [Tempo.SQL](Tempo.SQL.md): Top-level namespace for `ex_tempo_sql` — Ecto types, query macros and
migration helpers that store Tempo expressions as PostgreSQL ranges and
multiranges.

- Ecto types
  - [Tempo.Ecto.Interval](Tempo.Ecto.Interval.md): Ecto.ParameterizedType for persisting an interval as a
PostgreSQL `tstzrange` value.
  - [Tempo.Ecto.IntervalSet](Tempo.Ecto.IntervalSet.md): Ecto.ParameterizedType for persisting the intervals an expression
covers as a PostgreSQL `tstzmultirange` value (PostgreSQL 14+).
  - [Tempo.Ecto.Tempo](Tempo.Ecto.Tempo.md): 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.
  - [Tempo.Ecto.TempoMultirange](Tempo.Ecto.TempoMultirange.md): Ecto.ParameterizedType for the PostgreSQL composite type
`tempo_multirange` — a `tstzmultirange` paired with a
resolution string and `jsonb` metadata that together round-
trip a set, or any expression of several spans with ISO 8601 text,
without information loss.
  - [Tempo.Ecto.TempoRange](Tempo.Ecto.TempoRange.md): Ecto.ParameterizedType for the PostgreSQL composite type
`tempo_range` — a `tstzrange` paired with a Tempo-resolution
string and a `jsonb` metadata column that together preserve
the full Tempo shape on round-trip.

- Queries
  - [Tempo.Ecto.QueryAPI](Tempo.Ecto.QueryAPI.md): Ecto query fragments for PostgreSQL range operators, named after
Allen's interval algebra so queries read as English sentences.
  - [Tempo.Ecto.QueryAPI.Composite](Tempo.Ecto.QueryAPI.Composite.md): Ecto query fragments for the `tempo_range` and
`tempo_multirange` composite types — the same Allen-named
macros as `Tempo.Ecto.QueryAPI`, but auto-unwrapping the
`(column).range` / `(column).ranges` field so Postgres range
operators can apply.

- Setup
  - [Tempo.SQL.JSON](Tempo.SQL.JSON.md): Shim module that adapts Erlang's built-in `:json` (OTP 27+) to
Postgrex's expected JSON-library interface.
  - [Tempo.SQL.Migration](Tempo.SQL.Migration.md): Ecto migration helpers for the Tempo PostgreSQL range types.
  - [Tempo.SQL.PostgresTypes](Tempo.SQL.PostgresTypes.md): The Postgrex types for a repository that stores the composite
`tempo_range` and `tempo_multirange` columns.

- Exceptions
  - [Tempo.SQL.UnsupportedValueError](Tempo.SQL.UnsupportedValueError.md): Returned when a Tempo expression cannot be stored in a PostgreSQL
range type, its `:reason` saying why.

- Internals
  - [Tempo.SQL.Conversion](Tempo.SQL.Conversion.md): Internal helpers that translate between Tempo intervals and the
`DateTime` / `:unbound` values that `Postgrex.Range` understands.
  - [Tempo.SQL.Meta](Tempo.SQL.Meta.md): JSON encoding and decoding for the `meta` column of the
`tempo_range` and `tempo_multirange` composite types.

