I am developing a plugin to get familar with the platform and make some proof of concepts. I am trying to execute SQL commands to a local postgres database directly in my plugin through a button component.
Currently I am trying to run the command using, getDataSourceSrv to grab the user defined datasource from Grafana. Then I am using the query() to try and execute the command. Within this query I am setting my target as my query which is a SQL command. I have established that I am connecting to my database however I either receieve a Bad Request or dont seem to recieve any response.
Here is an example of my current implementation.
const datasource = await getDataSourceSrv().get('PostgreSQL')
console.log(datasource)
const response = await datasource.query({
requestId: 'A',
interval: '30s',
intervalMs: 30000,
maxDataPoints: 1000,
range: {
from: dateTime().subtract(1, 'h'),
to: dateTime(),
raw: {
from: 'now-1h',
to: 'now',
},
},
scopedVars: {},
targets: [query],
timezone: 'browser',
app: 'dashboard',
startTime: Date.now()
})
where query is
const query = "SELECT * FROM placeholder"