fr-ser / grafana-sqlite-datasource

Grafana Plugin to enable SQLite as a Datasource
Apache License 2.0
124 stars 17 forks source link

Support Query Variables #14

Closed JohnnyBee2 closed 3 years ago

JohnnyBee2 commented 3 years ago

Good job. Can you add Grafana variables to SQL?

fr-ser commented 3 years ago

Which ones? I am using a variable replacement function in the frontend

JohnnyBee2 commented 3 years ago

Variables created in dashboard settings ($var...). They don't work for me. Query inspector shows the empty space in the place of the variable.

fr-ser commented 3 years ago

Could you maybe export your dashboard as JSON and attach it here? For local development, I have a dashboard with a variable and it's working fine. Maybe I just need an exact reproducible case to see the problem. Here is the working dashboard: image

JohnnyBee2 commented 3 years ago

Hmmm, I created a new dashboard and did a series of tests. it seems to me that variables (not of type QUERY) are transferred correctly to SQL. My mistake, sorry. Thank you for your help.

But I have one more problem. Generating variables in dashboard settings as a query type does not work for me. Datasource works fine in tables - data is visible. The variables show nothing. Any suggestions?

image image image

fr-ser commented 3 years ago

Ok, query variables are something else here apparently. I haven't actively implemented the, but would have guessed, that they should be supported with the default settings. Seems like not :shrug: I will add this issue as a TODO. And take a stab later.

JohnnyBee2 commented 3 years ago

Thanks. I am waiting for the next version.

fr-ser commented 3 years ago

Hava a look at this release. Does it work for you? https://github.com/fr-ser/grafana-sqlite-datasource/releases/tag/v0.2.1

JohnnyBee2 commented 3 years ago

Variables in version 0.2.1 ZIP don't work for me. Variables in version 0.2.1 of TAR work fine. Thanks.

Do you have support for Options Multi-value? is: {var1, var2, var3, .......} maybe it should be: 'var1', 'var2', 'var3', ....... in query: select * from table where field1 in ($VAR)

Thanks again for a great job.

fr-ser commented 3 years ago

Weird. The zip worked for me :shrug:

And regarding multiple variables, have a look at formatting string here: https://grafana.com/docs/grafana/latest/variables/advanced-variable-format-options/#raw

Your example might need something like: select * from table where field1 in ($(VAR:csv))

JohnnyBee2 commented 3 years ago

Variables work very well. select * from table where field1 in (${VARs: doublequote}) It solved the problem Thanks

fr-ser commented 3 years ago

That is nice to hear. I will close the issue now. If something else regarding query variables comes up you can post here and I can reopen the issue or create a new issue :ok_hand: