mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
* 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
36 lines
572 B
Go
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
|
|
}
|