squll

package module
v0.0.0-...-b07eac8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 1, 2026 License: BSD-3-Clause Imports: 3 Imported by: 0

README

Simple SQL templating:

  • configurable placeholders ($1, :2, ?);
  • no external dependencies;

API


import "github.com/Zamony/go/squll"

var queryInsertScores = squll.Must(`
    INSERT INTO scores VALUES
    {{range $i, $v := .}}
        {{if $i}}, {{end}}
        ({{argument $v.Name}}, {{argument $v.Score}})
    {{end}}
`)

func insertScores() error {
    query, args, err := queryInsertScores.Build([]UserScores{
        {"Alice", 10},
        {"Bob",   20},
        {"Chris", 30},
    })
    if err != nil {
        return err
    }
    // Query:
    // INSERT INTO scores VALUES ($1, $2), ($3, $4), ($5, $6)

    // Args:
    // []any{"Alice", 10, "Bob", 20, "Chris", 30}
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultPlaceholderOption = WithDollarPlaceholder()

Functions

func WithColonPlaceholder

func WithColonPlaceholder() func(*config)

func WithDollarPlaceholder

func WithDollarPlaceholder() func(*config)

func WithQuestionPlaceholder

func WithQuestionPlaceholder() func(*config)

Types

type Template

type Template struct {
	// contains filtered or unexported fields
}

func Must

func Must(text string, options ...func(*config)) *Template

func (*Template) Build

func (t *Template) Build(data any) (string, []any, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL