Appearance
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 periodBefore the query runs, Diver:
- Removes comments (
-- …and/* … */). - Replaces each placeholder with SQL for the viewer's current filter choices, sending the chosen values to the database separately.
- 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
| Placeholder | Example | Read 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.
| Chart | What it reads |
|---|---|
| Bar, line, scatter, doughnut | The first column gives the labels (the x-axis, or the slices). Every other column is a series, named after the column. |
| Table | Every column and row, as returned. |
| Number | The 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. |
| Gauge | The 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. |
| Map | Columns 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. |
| Text | The 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 periodCaching
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.