Documentation
¶
Overview ¶
Package pageable is for page query based on GORM package
As a quick start:
func getResultSet (page int,rowsPerPage int)(*pageable.Response,error){
//your empty result set
resultSet := make([]*User,0,30)
//prepare a handler to query
handler := DB.
Module(&User{}).
Where(&User{Active:true})
//use PageQuery to get data
resp,err := pageable.PageQuery(page,rowsPerPage,handler,&resultSet)
// handle error
f err != nil {
panic(err)
}
And then you can print this value to see the page info
fmt.Println(resp.PageNow) //PageNow: current page of query fmt.Println(resp.PageCount) //PageCount: total page of the query fmt.Println(resp.RawCount) //RawCount: total raw of query fmt.Println(resp.RawPerPage) //RawPerPage: rpp fmt.Println(resp.ResultSet) //ResultSet: result data fmt.Println(resp.FirstPage) //FirstPage: if the result is the first page fmt.Println(resp.LastPage) //LastPage: if the result is the last page fmt.Println(resp.Empty) //Empty: if the result is empty }
And here a clear JSON object of the Response LIKE Spring Pageable
{
"PageNow": 2,
"PageCount": 1,
"RawCount": 1,
"RawPerPage": 25,
"ResultSet": [],
"FirstPage": false,
"LastPage": false,
"Empty": true
}
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SetRecovery ¶
func SetRecovery(handler func())
SetRecovery Set custom recovery Here are some sample of the custom recovery
package main
import (
"fmt"
pageable "github.com/BillSJC/gorm-pageable"
)
//your recovery
func myRecovery(){
if err := recover ; err != nil {
fmt.Println("something happened")
fmt.Println(err)
//then you can do some logs...
}
}
func init(){
//setup your recovery
pageable.SetRecovery(myRecovery)
}
func Use0AsFirstPage ¶
func Use0AsFirstPage()
Use0AsFirstPage : the default first page is 1. However,if u want to use 0 as the first page, just follow this step:
pageable.Use0AsFirstPage()
Types ¶
type Response ¶
type Response struct {
PageNow int //PageNow: current page of query
PageCount int //PageCount: total page of the query
RawCount int //RawCount: total raw of query
RawPerPage int //RawPerPage: rpp
ResultSet interface{} //ResultSet: result data
FirstPage bool //FirstPage: if the result is the first page
LastPage bool //LastPage: if the result is the last page
Empty bool //Empty: if the result is empty
}
Response: Base response of query
Click to show internal directories.
Click to hide internal directories.