Skip to content

Diver Query Language (DQL) ​

DQL is the SQL your database already speaks, plus a few placeholders in curly braces that connect a chart to the dashboard's filters. Every chart has one DQL query, which you write in the chart editor or in a *.diver.yml file.

sql
SELECT {created_at:aggregation} AS period, count(*) AS signups
FROM users
WHERE {created_at=timerange}
  AND {country=countries}
GROUP BY period
ORDER BY period

Before the query runs, Diver:

  1. Removes comments (-- … and /* … */).
  2. Replaces each placeholder with SQL for the viewer's current filter choices, sending the chosen values to the database separately.
  3. Runs the result on the chart's data source.

Everything outside curly braces is passed to the database unchanged, so use the SQL dialect of your source: PostgreSQL, Redshift, MySQL or Snowflake.

Placeholders ​

PlaceholderExampleRead more
Filter a column{created_at=timerange}, {country=countries}How filters work
Group by time{created_at:aggregation}, {created_at:month}Aggregation
Read a filter's selection{countries.values}, {timerange.start}Reading the selection

How results become charts ​

Each chart type reads the query's columns in its own way. Name and order your columns to match.

ChartWhat it reads
Bar, line, scatter, doughnutThe first column gives the labels (the x-axis, or the slices). Every other column is a series, named after the column.
TableEvery column and row, as returned.
NumberThe first row's value for each column. If there's a second row, the chart also shows the change from it, so order the rows newest first to compare with the previous period.
GaugeThe first row. The first column is the value; the columns after it are the boundaries of the gauge's colour bands, such as 0, 50, 80, 100.
MapColumns found by name. country, region, state, city, name or label gives the place, and lat/latitude with lon/lng/longitude gives points. value, count, total, amount or size gives the value that colours or sizes each place.
TextThe first row, as text.

For example, a line chart with one line per channel:

sql
SELECT {created_at:aggregation} AS period,
       count(*) FILTER (WHERE channel = 'web') AS web,
       count(*) FILTER (WHERE channel = 'app') AS app
FROM orders
WHERE {created_at=timerange}
GROUP BY period
ORDER BY period

Caching ​

Results are cached for as long as the dashboard's Data cache setting says (cache_ttl in a *.diver.yml file). Each combination of query and filter choices is cached separately.

When the cache period has ended, the next viewer still gets the cached result immediately, and Diver runs the query again in the background for the views after that. A result is never served more than five minutes after its cache period ended, which keeps dashboards fast.

With a cache of 0, nothing is cached: every view runs the query against your database and shows the latest data.

Reach new depths