Documentation ¶
Index ¶
- Variables
- type Option
- type Paging
- func (p *Paging) CalcTotalPage()
- func (p *Paging) Offset() int64
- func (p *Paging) SQL() string
- func (p *Paging) Scan(src interface{}) error
- func (p *Paging) SetTotalSize(totalSize int)
- func (p *Paging) SetupTotalSize(firstPageSize int, querier Querier, sql string, args ...interface{}) error
- func (p *Paging) SetupTotalSizeFunc(firstPageSize int, querier Querier, sqlFunc func() (string, error), ...) error
- type Querier
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var DefaultPageSize, MaxPageSize int64 = 10, 1000
Functions ¶
This section is empty.
Types ¶
type Paging ¶
type Paging struct { TotalSize int64 `json:"totalSize"` TotalPage int64 `json:"totalPage"` CurrentPage int64 `json:"-"` PageSize int64 `json:"-"` }
func New ¶
New returns a Paging from page, size in string type
Example ¶
paging := New("3", "20") fmt.Println(paging.SQL()) // we implemented sql.Scanner paging.Scan(int64(82)) fmt.Printf("%+v\n", paging)
Output: LIMIT 20 OFFSET 40 &{TotalSize:82 TotalPage:5 CurrentPage:3 PageSize:20}
func NewFromInt64 ¶
func NewFromQuery ¶
NewFromQuery returns a paging from url.Values
Example ¶
fmt.Printf("%+v\n", NewFromQuery(nil))
Output: &{TotalSize:0 TotalPage:0 CurrentPage:1 PageSize:10}
func (*Paging) CalcTotalPage ¶
func (p *Paging) CalcTotalPage()
func (*Paging) Scan ¶
Scan implemented sql.Scanner, so just use rows.Scan(paging).
Example ¶
p := NewFromInt64(1, 10) fmt.Println(p.Scan(10))
Output: paging: cannot assign int(10) to int64
func (*Paging) SetTotalSize ¶
func (*Paging) SetupTotalSize ¶
func (p *Paging) SetupTotalSize( firstPageSize int, querier Querier, sql string, args ...interface{}, ) error
Example ¶
p := NewFromInt64(1, 100) fmt.Println(p.SetupTotalSize(50, nil, "SELECT count(*)")) fmt.Printf("%+v\n", p) p = NewFromInt64(2, 100) fmt.Println(p.SetupTotalSize(50, testQuerier{}, "SELECT count(*)")) fmt.Printf("%+v\n", p)
Output: <nil> &{TotalSize:50 TotalPage:1 CurrentPage:1 PageSize:100} <nil> &{TotalSize:150 TotalPage:2 CurrentPage:2 PageSize:100}
func (*Paging) SetupTotalSizeFunc ¶
func (p *Paging) SetupTotalSizeFunc( firstPageSize int, querier Querier, sqlFunc func() (string, error), args ...interface{}, ) error
Example ¶
p := NewFromInt64(1, 100) fmt.Println(p.SetupTotalSizeFunc(50, nil, func() (string, error) { return "", nil })) fmt.Printf("%+v\n", p) p = NewFromInt64(2, 100) fmt.Println(p.SetupTotalSizeFunc(50, testQuerier{}, func() (string, error) { return "", nil })) fmt.Printf("%+v\n", p)
Output: <nil> &{TotalSize:50 TotalPage:1 CurrentPage:1 PageSize:100} <nil> &{TotalSize:150 TotalPage:2 CurrentPage:2 PageSize:100}
Click to show internal directories.
Click to hide internal directories.