Skip to content

deadblue/sqltmpl

Repository files navigation

SQL-Template

A template engine for SQL in Golang.

Example

import (
    "github.com/deadblue/sqltmpl"
)

func main() {
    tmpl := sqltmpl.MustParse[string](
        "SELECT * FROM table WHERE id = {{ . }}",
    )
    var query string
    var args []any

    query, args = tmpl.MustRender("a")
    // query: SELECT * FROM table WHERE id = ?
    // args: ["a"]

    query, args = tmpl.MustRender("b")
    // query: SELECT * FROM table WHERE id = ?
    // args: ["b"]
}

Specification

The SQL template follows the specification of standard package "text/template" with some limitations in below:

  • Function/Method calling is unsupported.
  • Chained pipelines is unsupported.
  • Variable definition is unsupported.

License

MIT

About

A template engine for SQL in Golang.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages