query

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package query 查询操作

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PagingResponser added in v0.6.0

func PagingResponser[T any](ctx *web.Context, l *Limit, sql *sqlbuilder.SelectStmt) web.Responser

PagingResponser 将分页对象封装成 web.Responser

T 为返回给客户端数据元素项的类型,必须为非指针类型。最终给客户的数据为 []*T。

Types

type DateRange

type DateRange struct {
	Start time.Time
	End   time.Time
}

DateRange 时间范围。

将查询参数中的 xx-xx 转换成两个时间戳。

其中 0 表示未传递过来。

func (*DateRange) UnmarshalQuery

func (s *DateRange) UnmarshalQuery(data string) error

type Limit

type Limit struct {
	Page int `query:"page,0"`  // 请求的页码,从 0 开始。
	Size int `query:"size,20"` // 每页的数量
}

Limit 分页查询中总会带的查询参数

func (*Limit) CTXSanitize

func (l *Limit) CTXSanitize(v *web.Validation)

type Page added in v0.6.0

type Page[T any] struct {
	XMLName struct{} `json:"-" xml:"page"`
	Count   int64    `json:"count" xml:"count,attr"`                   // 符合条件的所有数据
	Current []*T     `json:"current"  xml:"current"`                   // 当前页的数据
	More    bool     `json:"more,omitempty" xml:"more,attr,omitempty"` // 是否还有更多的数据
}

Page 分页对象

func Paging

func Paging[T any](ctx *web.Context, l *Limit, sql *sqlbuilder.SelectStmt) (*Page[T], error)

Paging 返回分页对象

T 为返回给客户端数据元素项的类型,必须为非指针类型。最终给客户的数据为 []*T。

type Text

type Text struct {
	Limit
	Text string `query:"text"`
}

Text 带分页的文字查询

Jump to

Keyboard shortcuts

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