gormutil

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2023 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultLimit = 15

DefaultLimit define the default number of records to be retrieved.

Variables

This section is empty.

Functions

func Paginator added in v0.3.1

func Paginator(req *ListRequest) func(db *gorm.DB) *gorm.DB

Paginator returns a gorm scope paginator.

Types

type LimitAndOffset

type LimitAndOffset struct {
	Offset int
	Limit  int
}

LimitAndOffset contains offset and limit fields.

type ListRequest

type ListRequest struct {
	// Page
	Page int `form:"page"`

	// Offset
	Offset int `form:"offset"`

	// Limit
	Limit int `form:"limit"`

	// Order by field.
	Order string `form:"order"`

	// Sort: asc or desc.
	Sort string `form:"sort"`
}

func (*ListRequest) SetDefaultParams

func (req *ListRequest) SetDefaultParams()

SetDefaultParams Set default params if not exist.

type ListResponse

type ListResponse struct {
	Total int64 `json:"total"`
	Data  any   `json:"data"`
}

func Paginate

func Paginate(db *gorm.DB, req *ListRequest, data any) (res *ListResponse, err error)

Paginate the query.

Jump to

Keyboard shortcuts

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