grafana-diagram icon indicating copy to clipboard operation
grafana-diagram copied to clipboard

Support for direct definition via query results

Open CharlyRipp opened this issue 3 years ago • 1 comments

In my use-case I'm querying a SQL database for non-series data, specifically a prerequisites structure.

It would be nice to format the query result to produce mermaid syntax then directly use the query output in the diagram definition.

For example, I could fill in the Diagram definition with

stateDiagram-v2
    $A

$A (bad example) referencing the A table query containing something like:

select GROUP_CONCAT(concat(coalesce(pt.name, '[*]'), ' --> ', coalesce(t.name, '[*]')) SEPARATOR '\n')
from tasks t
left outer join prereqs p on t.id = p.task_id
left outer join tasks pt on pt.id = p.prereq_id
where t.job_id = '...'

Resulting in:

    [*] --> TASK_1
    TASK_1 --> TASK_2
    TASK_2 --> TASK_3.1
    TASK_2 --> TASK_3.2
    TASK_3.1 --> TASK_4
    TASK_3.2 --> TASK_4

Thus creating diagram definition of:

stateDiagram-v2
    [*] --> TASK_1
    TASK_1 --> TASK_2
    TASK_2 --> TASK_3.1
    TASK_2 --> TASK_3.2
    TASK_3.1 --> TASK_4
    TASK_3.2 --> TASK_4

There's probably a better way, but having this flexibility could be a catch-all for other awkward use-cases.

CharlyRipp avatar Mar 31 '22 17:03 CharlyRipp

Interesting use-case!

jdbranham avatar Apr 08 '22 20:04 jdbranham