page

package module
v0.0.0-...-7ec0b4a Latest Latest
Warning

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

Go to latest
Published: May 28, 2018 License: MIT Imports: 3 Imported by: 0

README

page

  • go get pkg & import
go get github.com/xorm-page/page
  • query
// FindByCondition dynamic query
func (p *PackageMapper) FindByCondition(condition *Package, pa *page.Pageable) (*page.Page, error) {
	var pkgs []Package
	session := engine.Alias("p").Where("1=1")
	if condition != nil {
		if condition.UserID != "" {
			session.And("p.user_id = ?", condition.UserID)
		}
		if condition.Name != "" {
			log.Debugf("pkg_name=%s", condition.Name)
			session.And("p.pkg_name LIKE ?", "%"+condition.Name+"%")
		}
	}

	return page.NewBuilder().Page(pa).Session(session).Data(&pkgs).Build()
}
  • Response body for rest api by unmarshal 'Page' struct.
{
  "page_index": 2,
  "page_size": 3,
  "pages": 2,
  "total": 6,
  "data": [
    {
      "id": 4,
      "name": "test5",
      "source": "https://github.com/xogopkg/test",
      "description": "test pkg",
      "created_at": "2018-03-09T21:12:19+08:00",
      "updated_at": "2018-03-09T21:12:19+08:00",
      "user_id": "1a08b350-0ed1-4a59-b0c9-5706882bd19b"
    },
    {
      "id": 5,
      "name": "test6",
      "source": "https://github.com/xogopkg/test",
      "description": "test pkg",
      "created_at": "2018-03-09T21:12:19+08:00",
      "updated_at": "2018-03-09T21:12:19+08:00",
      "user_id": "1a08b350-0ed1-4a59-b0c9-5706882bd19b"
    },
    {
      "id": 6,
      "name": "test7",
      "source": "https://github.com/xogopkg/test",
      "description": "test pkg",
      "created_at": "2018-03-09T21:12:19+08:00",
      "updated_at": "2018-03-09T21:12:19+08:00",
      "user_id": "1a08b350-0ed1-4a59-b0c9-5706882bd19b"
    }
  ]
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetLogger

func SetLogger(clogger CLogger)

SetLogger set looger

Types

type Builder

type Builder struct {
	// contains filtered or unexported fields
}

Builder page builder

func NewBuilder

func NewBuilder() *Builder

NewBuilder new page builder

func (*Builder) Build

func (p *Builder) Build() (*Page, error)

Build return page struct

func (*Builder) Data

func (p *Builder) Data(dataType interface{}) *Builder

Data set page data

func (*Builder) Page

func (p *Builder) Page(pa *Pageable) *Builder

Page init page index & size

func (*Builder) Session

func (p *Builder) Session(session *xorm.Session) *Builder

Session set xorm session

type CLogger

type CLogger interface {
	Debug(v ...interface{})
	Debugf(formater string, v ...interface{})
}

Logger logger interface

func Logger

func Logger() CLogger

Logger get logger

type Page

type Page struct {
	PageIndex int         `json:"page_index,omitempty"`
	PageSize  int         `json:"page_size,omitempty"`
	Pages     int64       `json:"pages,omitempty"`
	Total     int64       `json:"total,omitempty"`
	Data      interface{} `json:"data"`
}

Page page

func NewPage

func NewPage(data interface{}) *Page

NewPage page

type Pageable

type Pageable struct {
	PageIndex int
	PageSize  int
	// offset    int
	Sort Sort
}

Pageable pageable

func (*Pageable) Check

func (p *Pageable) Check() error

Check verify page inde & page size.

func (*Pageable) SetDefault

func (p *Pageable) SetDefault()

SetDefault default page

type PageableMapper

type PageableMapper struct {
}

PageableMapper pageable base mapper

func (*PageableMapper) Builder

func (p *PageableMapper) Builder() *Builder

Builder get mapper Builder

type Sort

type Sort struct {
	Sortby string
	Order  string
}

Sort sort

Jump to

Keyboard shortcuts

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