July 22, 2022: Help us out by filling out a short user survey!
Back to documentation

Database Panels

Database panels allow you to query databases either locally or through an SSH proxy. You must first configure a data source for the database you want to connect to. Then you can create a database panel and select the data source you created.

Basic database panel

Reading from other panels

MySQL, PostgreSQL and SQLite panels support the DM_getPanel($panel) function. You can either pass a panel index or the panel name. If you pass the panel name it must be quoted as a string literal.

The result of calling DM_getPanel($panel) is a temporary table is created with the data from that panel. You can reference that table with the entire DM_getPanel($panel) call or with the t_$panel table alias. Multiple DM_getPanel calls for the same panel will not result in reloading of the panel into a temporary table.

DM_getPanel result format requirements

You can only call DM_getPanel($panel) on a panel that returns an array of objects. If the array of objects is nested within the panel result then you can specify a path to the array of objects in the second argument of the DM_getPanel call.

For example if you have a JSON data structure like this in one panel:

{
  "data": {
    "data": [
      {"id": 1, "name": "Corah"},
      {"id": 3, "name": "Minh"}
    ]
  },
  "total": 2
}

You could run a SQL query against that panel like:

SELECT * FROM DM_getPanel(0, 'data.data')

Macros

All panels that have a panel body can use macros. So for panels that don't support the DM_getPanel function call (panels that are not MySQL, PostgreSQL or SQLite) you can still use macros to fetch another panel's result.

Read more about macros here.

Connecting via SSH proxy

If you define an SSH connection you will be able to select the server to proxy your database connection through an SSH tunnel.

NOTE: In some versions (including 0.9.0) there may be a bug where you need to specify localhost in the Data Source configuration. Normally the default would be set to localhost if you didn't set it.

Basic database panel via server

PostgreSQL

If you are not running your PostgreSQL with TLS, you will need to disable sslmode in your connection. Append ?sslmode=disable to the database address. For example if you are running PostgreSQL locally you might set the database address to localhost?sslmode=disable.

Supported Databases

Traditional SQL

Warehouse

Document

Apps

Time Series

Metrics

About this page

See an error or want to add a clarification? This page is generated from this file on Github.

Last edited Jun 23, 2022.