Documentation
¶
Overview ¶
Example ¶
package main import ( "fmt" "github.com/deadblue/sqltmpl" ) type Params struct { Ids []int Type string } func main() { tmpl := sqltmpl.MustParse[Params]( "SELECT a, b, c FROM table WHERE id IN (", "{{- range $index, $elem := .Ids -}}", "{{ if $index }}, {{ end }}{{ $elem }}", "{{- end -}}", ") AND type = {{ .Type }}", ) query, args := tmpl.MustRender(Params{ Ids: []int{1, 2, 3}, Type: "foobar", }) fmt.Printf("Query: %s\n", query) fmt.Printf("Arguments: %v", args) }
Output: Query: SELECT a, b, c FROM table WHERE id IN (?, ?, ?) AND type = ? Arguments: [1 2 3 foobar]
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Template ¶
type Template[P any] interface { // Render renders template with given params. // // The result is rendered query statement, corresponding SQL arguments, and // an error that will be not-nil when rendering failed. Render(params P) (query string, args []any, err error) // MustRender is like [Render] but panics when rendering failed. MustRender(params P) (query string, args []any) }
Click to show internal directories.
Click to hide internal directories.