Created by
Richard Bucker
| package main
import (
"bytes"
"log"
"text/template"
"github.com/gchaincl/dotsql"
)
var (
doc = `
-- name: hello_cte
hello_cte (hello) as (select 'HELLO')
-- name: hello
;with
{{.hello_cte}}
select * from hello_cte
`
)
func main() {
d, err := dotsql.LoadFromString(doc)
if err != nil {
log.Printf("ERROR: %v", err)
}
sql, err := d.Raw("hello")
if err != nil {
log.Printf("ERROR: %v", err)
}
tmpl := template.Must(template.New("dotsql").Parse(sql))
buf := bytes.NewBufferString("")
err = tmpl.Execute(buf, d.QueryMap())
if err != nil {
log.Printf("ERROR: %v", err)
}
log.Printf("Finished:\n%s\n", buf)
}
|