Files
grafana/pkg/services/store/entity/sqlstash/sqltemplate/sqltemplate.go
Diego Augusto Molina cbcd945251 Unified Storage: in SQL template, also handle output data, improve API, examples and docs (#87560)
* preview of work so far

* stylistic improvements

* fix linters

* remove golden tests, they may cause the system to be too rigid to changes

* remove unnecessary code for golden tests

* remove white space mangling in Execute

* also handle output data, improve API, examples and docs

* add helper methods

* fix interface
2024-05-14 12:32:21 -03:00

36 lines
572 B
Go

package sqltemplate
import (
"strings"
"text/template"
)
type SQLTemplate struct {
Dialect
Args
ScanDest
}
func New(d Dialect) *SQLTemplate {
return &SQLTemplate{
Dialect: d,
}
}
type SQLTemplateIface interface {
Dialect
GetArgs() Args
GetScanDest() ScanDest
}
// Execute is a trivial utility to execute and return the results of any
// text/template as a string and an error.
func Execute(t *template.Template, data any) (string, error) {
var b strings.Builder
if err := t.Execute(&b, data); err != nil {
return "", err
}
return b.String(), nil
}