Bosca / Analytics

Queries

One query, every chart

A saved query is SQL plus a typed parameter list. It's the single source of truth every visualization and dashboard draws from — get the number right once, in one place, and everything downstream follows.

Anatomy of a query

SQL, plus its inputs

Every query has a stable key you reference it by, a readable name and description, the SQL body itself, and a list of typed parameters. Charts and dashboards don't copy the SQL — they run the query, so there's exactly one definition to maintain.

  • The key is the handle code and dashboards reference — distinct from the display name, so renaming a query never breaks a link.
  • Each parameter carries a name, a type, an optional default, and a required flag.
  • Run the SQL right in the detail page with parameter inputs and preview the rows inline.
sessions-by-day
-- key: sessions-by-day
SELECT date_trunc('day', created) AS day,
       count(*) AS sessions
FROM events
WHERE type = 'session'
  AND app = :appId
  AND created >= :from
GROUP BY 1 ORDER BY 1

Typed parameters

Inputs with a type

A parameter isn't just a placeholder — it declares its type, so a date range is a date range and an id list is an array. The same query serves one app or a whole fleet; you just change the inputs.

STRINGINTEGERFLOATBOOLEANDATEDATETIMETIMEARRAYOBJECTARRAY<of any type>

Git-backed queries

Your SQL, in version control

A query can bind to a SQL file in a Git repository and sync both ways. Push a change and the query updates in Studio; edit it in Studio and it commits back to the file, with author info.

  • Parameter definitions travel with the SQL, so a file carries its own typed inputs.
  • Review query changes in a pull request like any other code.
two-way sync
Gitsessions-by-day.sql
Studiosaved query

Caching

Fast dashboards, fresh numbers

Opt a query into result caching and each distinct set of parameters is cached and refreshed on an interval by a background job. A dashboard loads from cache instantly, and consumers can tell a cached result from a live one and see when it was last computed.

  • Every parameter combination is cached on its own, so a per-app view and a fleet view each stay warm.
  • Trigger a refresh on demand to recompute every cached combination at once.
cached results
appId = acme-webcached · 2m ago
appId = acme-ioscached · 2m ago
appId = acme-web · 90drefreshing…
refresh interval · 5 min

Keep exploring

More on Analytics