sqlbuilder

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2019 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var LimitMaxDefault uint = 600

LimitMaxDefault is used in SQLBuilder.Paginate() if SQLBuilder.LimitMax equals 0.

Functions

This section is empty.

Types

type BindFunc

type BindFunc func(stmt *sqlite.Stmt, startParam int) int

BindFunc is a function that binds one or more values to a sqlite.Stmt. A valid BindFunc must use startParam as the first param index for any binds and must return the total number of parameters bound.

type SQLBuilder

type SQLBuilder struct {
	strings.Builder
	Binds []BindFunc

	LimitMax uint // Max limit allowed by Paginate()
}

SQLBuilder prepares a sqlite.Stmt that has variable numbers of Binds.

func (*SQLBuilder) Append

func (s *SQLBuilder) Append(sql string, binds ...BindFunc)

Append sql and any associated binds.

Do not include a `;` in sql.

The sum of the binds return values must equal the number of params (e.g. "?") in sql or else s.Prep will panic.

func (*SQLBuilder) BindNParams

func (s *SQLBuilder) BindNParams(n int, binds ...BindFunc)

BindNParams appends n comma separated params placeholders (e.g. "?, ?, ... , ?") and append the binds.

Do not include a `;` in sql.

The sum of the binds return values must equal n or else s.Prep will panic.

func (*SQLBuilder) OrderBy

func (s *SQLBuilder) OrderBy(col, ascDesc string)

OrderBy append fmt.Sprintf(` ORDER BY %q %s`, col, order). No binds are added.

func (*SQLBuilder) OrderByPaginate

func (s *SQLBuilder) OrderByPaginate(col, order string, page, limit uint)

OrderByPaginate calls s.OrderBy() and then s.Paginate().

func (*SQLBuilder) Paginate

func (s *SQLBuilder) Paginate(page, limit uint)

Paginate appends ` LIMIT ?, ?` and the appropriate page and limit binds.

func (*SQLBuilder) Prep

func (s *SQLBuilder) Prep(conn *sqlite.Conn) *sqlite.Stmt

Prep prepares a sqlite.Stmt on conn using s.String() with a trailing `;` as the SQL, and then sequentially calls all s.Binds using the Stmt and the appropriate startParam. The Stmt is returned ready for its first Step().

If the total number of binds reported by the Binds differs from the total number of params reported by the Stmt, then Prep panics.

Jump to

Keyboard shortcuts

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