Hi,
I was wondering if MySQL is supported with scenes.
I setup a scene query runner:
const DATASOURCE_MYSQL = {
type: 'mysql',
uid: 'custom-mysql-datasource',
}
const queryRunner = new SceneQueryRunner({
queries: [
{
refId: 'A',
datasource: DATASOURCE_MYSQL,
query: 'SELECT * FROM customer',
},
],
});
// Part of the scene response
new SceneFlexItem({
width: '100%',
height: 300,
body: PanelBuilders.table()
.setTitle('Customers')
.setData(queryRunner)
.build()
});
I don’t seem to be able to get it working. When I look at the implementations of DataQuery
from @grafana/scenes
I don’t see a MySQL implementation so is MySQL not supported or am I missing something?
1 Like
Hi Ashley,
I was playing around a bit and it seems you need to use rawSql
property not query
for mySQL datasources. Also format property (either ‘table’ or ‘time_series’).
For you it could be:
const DATASOURCE_MYSQL = {
type: 'mysql',
uid: 'custom-mysql-datasource',
}
const queryRunner = new SceneQueryRunner({
queries: [
{
refId: 'A',
datasource: DATASOURCE_MYSQL,
format: 'table',
rawSql: 'SELECT * FROM customer',
},
],
});
// Part of the scene response
new SceneFlexItem({
width: '100%',
height: 300,
body: PanelBuilders.table()
.setTitle('Customers')
.setData(queryRunner)
.build()
});
Please, let me know if this works for you.
Yeah, that worked, how did you find that?
So there would be a JSON panel in the old Dashboards framework, and for MySQL datasource, there would be these two properties. Then I also looked at the request payload while running your code, and something like this showed up:
datasourceId: 2
intervalMs: 60000
maxDataPoints: 500
rawSql: ""
refId: "A"
The rawSql is empty. So I tried the rawSql
and format
as in the old framework.
It would be nice to have more explanation in documentation for scenes.