Fude.Query (Fude v0.1.0)

Copy Markdown View Source

A chart's data from an Ecto query, grouped and aggregated in the database: a chart of fifty million rows reads a few hundred.

Fude.bar(Fude.query(Order, Repo), x: :status, y: {:count, :id})

from(o in Order, where: o.shop_id == ^shop.id)
|> Fude.query(Repo)
|> Fude.line(x: {:month, :inserted_at}, y: {:sum, :total}, color: :channel)

For each layer, one GROUP BY query reads the channels that are not aggregated (a field, its unit of time, its bin) and the aggregates of the others (count, sum, mean, min, max, distinct). A histogram reads the least and the greatest value first, for its bins. PostgreSQL, MySQL and SQLite run them, each with its own functions of dates.

A layer with no aggregate (a scatter of points), a median, or small multiples read the rows' fields instead, only those the chart draws, at most :limit rows.

The query may have its own where, join and order_by; the order is dropped for the groups. Masu's grids give their filtered rows as a query (Masu.Live.selected/1): a chart of what a grid shows.

Options

  • :repo_opts - options for each call to the repo, such as prefix:.
  • :limit - the most rows read when they are read as they are; 100,000 when not given.

Summary

Functions

The data of an Ecto query or schema, read by repo.

Types

t()

@type t() :: %Fude.Query{
  limit: pos_integer(),
  query: Ecto.Query.t(),
  repo: module(),
  repo_opts: keyword()
}

Functions

new(queryable, repo, opts \\ [])

@spec new(Ecto.Queryable.t(), module(), keyword()) :: t()

The data of an Ecto query or schema, read by repo.