Documentation
¶
Overview ¶
Package sqlbpager applies a sqlkit.Pager to a go-sqlbuilder SelectBuilder.
It lives in a subpackage so that the root sqlkit package does not depend on go-sqlbuilder.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Apply ¶
func Apply(sb *sqlbuilder.SelectBuilder, p *sqlkit.Pager)
Apply adds the keyset condition, ORDER BY, LIMIT (size+1) and OFFSET of p to sb.
Note: sb.OrderBy of go-sqlbuilder APPENDS columns, while sb.Asc()/sb.Desc() set the direction of the whole list; do not call them together with Apply. Check p.Err() before executing the query.
Example ¶
package main
import (
"fmt"
"github.com/huandu/go-sqlbuilder"
"github.com/boostgo/sqlkit"
"github.com/boostgo/sqlkit/sqlbpager"
)
func main() {
p := sqlkit.OffsetPager(sqlkit.PageRequest{Page: 2, Size: 10}, sqlkit.Asc("id"))
sb := sqlbuilder.NewSelectBuilder()
sb.Select("id").From("users")
sb.Where(sb.Equal("tenant", "acme"))
sqlbpager.Apply(sb, p)
query, args := sb.BuildWithFlavor(sqlbuilder.PostgreSQL)
fmt.Println(query)
fmt.Println(args)
}
Output: SELECT id FROM users WHERE tenant = $1 ORDER BY id ASC LIMIT $2 OFFSET $3 [acme 11 10]
Types ¶
This section is empty.