Tempo. Ecto. QueryAPI
(Tempo SQL v0.1.0)
View Source
Ecto query fragments for PostgreSQL range operators, named after Allen's interval algebra so queries read as English sentences.
Each macro expands to a fragment/2 using the corresponding
PostgreSQL operator. The macros are require-able from any
Ecto query module:
import Ecto.Query
import Tempo.Ecto.QueryAPI
from m in Meeting, where: overlaps(m.window, ^iv)The mapping to Postgres operators:
contains/2→@>— "doesafully containb?"overlaps/2→&&— "doaandbshare any instant?" Matches Allen'soverlaps,overlapped_by,starts,started_by,during,contains,finishes,finished_by,equals— i.e. any non-disjoint pair.meets/2→-|-— "isaimmediately adjacent tob?" Matches Allen'smeetsandmet_by.strictly_before/2→<<— Allen'sprecedes.strictly_after/2→>>— Allen'spreceded_by.
The right-hand operand in each macro should be a Postgrex.Range
or Postgrex.Multirange — i.e. either a range literal or a value
produced by dumping a Tempo.Ecto.Interval /
Tempo.Ecto.IntervalSet field. The Ecto field type on the left
handles the conversion automatically when you pin a Tempo value
via ^ in the query.