Documentation ¶
Index ¶
- Variables
- type BindFunc
- type SQLBuilder
- func (s *SQLBuilder) Append(sql string, binds ...BindFunc)
- func (s *SQLBuilder) BindNParams(n int, binds ...BindFunc)
- func (s *SQLBuilder) OrderBy(col, ascDesc string)
- func (s *SQLBuilder) OrderByPaginate(col, order string, page, limit uint)
- func (s *SQLBuilder) Paginate(page, limit uint)
- func (s *SQLBuilder) Prep(conn *sqlite.Conn) *sqlite.Stmt
Constants ¶
This section is empty.
Variables ¶
var LimitMaxDefault uint = 600
LimitMaxDefault is used in SQLBuilder.Paginate() if SQLBuilder.LimitMax equals 0.
Functions ¶
This section is empty.
Types ¶
type BindFunc ¶
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.