Documentation ¶
Index ¶
- Variables
- func InTx(ctx context.Context, opts *sql.TxOptions, db *sql.DB, do func(db DB) error) (err error)
- type Config
- type DB
- type End
- type Option
- type Placeholder
- type QueryRunner
- type QueryStatement
- func (qs *QueryStatement[Param, Dest]) All(ctx context.Context, db DB, param Param) (result []Dest, err error)
- func (qs *QueryStatement[Param, Dest]) First(ctx context.Context, db DB, param Param) (result Dest, err error)
- func (qs *QueryStatement[Param, Dest]) Get(ctx context.Context) *QueryRunner[Dest]
- func (qs *QueryStatement[Param, Dest]) One(ctx context.Context, db DB, param Param) (result Dest, err error)
- func (qs *QueryStatement[Param, Dest]) Put(err error, runner *QueryRunner[Dest])
- type Raw
- type Runner
- type SQL
- type Scanner
- type Start
- type Statement
- func (s *Statement[Param]) Exec(ctx context.Context, db DB, param Param) (result sql.Result, err error)
- func (s *Statement[Param]) Get(ctx context.Context) *Runner
- func (s *Statement[Param]) Put(err error, runner *Runner)
- func (s *Statement[Param]) Query(ctx context.Context, db DB, param Param) (rows *sql.Rows, err error)
- func (s *Statement[Param]) QueryRow(ctx context.Context, db DB, param Param) (row *sql.Row, err error)
- type TemplateOption
- func Funcs(fm template.FuncMap) TemplateOption
- func Lookup(name string) TemplateOption
- func MissingKeyError() TemplateOption
- func MissingKeyInvalid() TemplateOption
- func MissingKeyZero() TemplateOption
- func New(name string) TemplateOption
- func Parse(text string) TemplateOption
- func ParseFS(fs fs.FS, patterns ...string) TemplateOption
- func ParseFiles(filenames ...string) TemplateOption
- func ParseGlob(pattern string) TemplateOption
Constants ¶
This section is empty.
Variables ¶
var ErrTooManyRows = errors.New("too many rows")
ErrTooManyRows is returned from One, when there are more than one rows.
Functions ¶
Types ¶
type Config ¶ added in v0.0.60
type Config struct { Start Start End End Placeholder Placeholder TemplateOptions []TemplateOption }
Config groups the available options.
type DB ¶
type DB interface { QueryContext(ctx context.Context, str string, args ...any) (*sql.Rows, error) QueryRowContext(ctx context.Context, str string, args ...any) *sql.Row ExecContext(ctx context.Context, str string, args ...any) (sql.Result, error) }
DB is implemented by *sql.DB and, *sql.Tx.
type Option ¶ added in v0.0.60
type Option interface {
Configure(config *Config)
}
Options are used to configure the statements.
type Placeholder ¶ added in v0.1.5
type Placeholder string
Placeholder can be static or positional using a go-formatted string ('%d').
func (Placeholder) Configure ¶ added in v0.1.5
func (p Placeholder) Configure(config *Config)
Configure implements the Option interface.
type QueryRunner ¶ added in v0.1.5
QueryRunner groups the relevant data for each 'run' of a QueryStatement.
func (*QueryRunner[Dest]) Reset ¶ added in v0.1.5
func (qr *QueryRunner[Dest]) Reset()
Reset the QueryRunner for the next run of a statement.
type QueryStatement ¶ added in v0.0.60
type QueryStatement[Param, Dest any] struct { // contains filtered or unexported fields }
QueryStatement is a QueryRunner pool and a type-safe sql query executor.
func QueryStmt ¶ added in v0.0.60
func QueryStmt[Param, Dest any](opts ...Option) *QueryStatement[Param, Dest]
QueryStmt creates a type-safe QueryStatement using variadic options. Define the mapping of a column to a struct field here using the Scan functions. Invalid templates panic.
func (*QueryStatement[Param, Dest]) All ¶ added in v0.0.60
func (qs *QueryStatement[Param, Dest]) All(ctx context.Context, db DB, param Param) (result []Dest, err error)
All returns a slice of Dest for each row.
func (*QueryStatement[Param, Dest]) First ¶ added in v0.0.60
func (qs *QueryStatement[Param, Dest]) First(ctx context.Context, db DB, param Param) (result Dest, err error)
First returns the first row mapped into Dest.
func (*QueryStatement[Param, Dest]) Get ¶ added in v0.1.10
func (qs *QueryStatement[Param, Dest]) Get(ctx context.Context) *QueryRunner[Dest]
Get a QueryRunner from the pool and execute the start option.
func (*QueryStatement[Param, Dest]) One ¶ added in v0.0.60
func (qs *QueryStatement[Param, Dest]) One(ctx context.Context, db DB, param Param) (result Dest, err error)
One returns exactly one Dest. If there is more than one row in the result set, ErrTooManyRows is returned.
func (*QueryStatement[Param, Dest]) Put ¶ added in v0.1.10
func (qs *QueryStatement[Param, Dest]) Put(err error, runner *QueryRunner[Dest])
Put a QueryRunner into the pool and execute the end option.
type Raw ¶ added in v0.0.20
type Raw string
Raw is used to write strings directly into the sql output. It should be used carefully.
type Runner ¶
type Runner struct { Context context.Context Template *template.Template SQL *SQL Args []any Location string }
Runner groups the relevant data for each 'run' of a Statement.
type SQL ¶ added in v0.0.40
type SQL struct {
// contains filtered or unexported fields
}
SQL implements io.Writer and fmt.Stringer.
type Scanner ¶
A Scanner is used to map columns to struct fields. Value should be a pointer to a struct field.
type Start ¶ added in v0.1.5
type Start func(runner *Runner)
Start is executed when a Runner is returned from a statement pool.
type Statement ¶ added in v0.0.60
type Statement[Param any] struct { // contains filtered or unexported fields }
Statements is a Runner pool and a type-safe sql executor.
func Stmt ¶ added in v0.0.60
Stmt creates a type-safe Statement using variadic options. Invalid templates panic.
func (*Statement[Param]) Exec ¶ added in v0.0.60
func (s *Statement[Param]) Exec(ctx context.Context, db DB, param Param) (result sql.Result, err error)
Exec takes a runner and executes it.
func (*Statement[Param]) Get ¶ added in v0.1.5
Get a Runner from the pool and execute the start option.
func (*Statement[Param]) Put ¶ added in v0.1.5
Put a Runner into the pool and execute the end option.
type TemplateOption ¶ added in v0.1.5
TemplateOption can be used to configure the template of a statement.
func Funcs ¶ added in v0.0.60
func Funcs(fm template.FuncMap) TemplateOption
Funcs is equivalent to the method from text/template.
func Lookup ¶ added in v0.0.60
func Lookup(name string) TemplateOption
Lookup is equivalent to the method from text/template.
func MissingKeyError ¶ added in v0.0.60
func MissingKeyError() TemplateOption
MissingKeyError is equivalent to the method 'Option("missingkey=error")' from text/template.
func MissingKeyInvalid ¶ added in v0.0.60
func MissingKeyInvalid() TemplateOption
MissingKeyInvalid is equivalent to the method 'Option("missingkey=invalid")' from text/template.
func MissingKeyZero ¶ added in v0.0.60
func MissingKeyZero() TemplateOption
MissingKeyZero is equivalent to the method 'Option("missingkey=zero")' from text/template.
func Parse ¶ added in v0.0.60
func Parse(text string) TemplateOption
Parse is equivalent to the method from text/template.
func ParseFS ¶ added in v0.0.60
func ParseFS(fs fs.FS, patterns ...string) TemplateOption
ParseFS is equivalent to the method from text/template.
func ParseFiles ¶ added in v0.0.60
func ParseFiles(filenames ...string) TemplateOption
ParseFiles is equivalent to the method from text/template.
func ParseGlob ¶ added in v0.0.60
func ParseGlob(pattern string) TemplateOption
ParseGlob is equivalent to the method from text/template.
func (TemplateOption) Configure ¶ added in v0.1.5
func (to TemplateOption) Configure(config *Config)
Configure implements the Option interface.