Generated SQL for time-bucketed queries (spec §9.1).
Elixir functions returning SQL fragments — no C extension, no custom query language. Level 1 of the query layer: the common case as a single call. Everything here degrades gracefully to level 3 — the generated SQL is plain SQLite, runnable by hand.
Summary
Functions
Bucket width of {n, unit} expressed in the database's time unit.
Runs a bucketed aggregate query against a metric (spec §9.2 level 1).
The time_bucket hyperfunction as a SQL fragment (spec §9.1):
integer division and multiply on epoch timestamps.
Functions
@spec bucket_width( {pos_integer(), atom()}, atom() ) :: pos_integer()
Bucket width of {n, unit} expressed in the database's time unit.
@spec run(Barograph.db(), String.t(), keyword()) :: {:ok, [map()]} | {:error, term()}
Runs a bucketed aggregate query against a metric (spec §9.2 level 1).
Options
:labels- label filter map; matched withjson_extracton the series' labels. A series matches if it carries at least the given pairs.:from,:to-DateTimeor integer epoch in the database's time unit.fromis inclusive,toexclusive.:bucket-{n, unit}where unit is:second,:minute,:hour,:day, or:week. Required when:aggis given.:agg- one of:avg,:min,:max,:sum,:count.
Without :bucket, returns raw samples as %{ts, value} maps, ordered
by time. With :bucket, returns %{bucket, value} maps where
bucket is the bucket start epoch in the database's time unit.
@spec time_bucket(String.t(), pos_integer()) :: String.t()
The time_bucket hyperfunction as a SQL fragment (spec §9.1):
integer division and multiply on epoch timestamps.