dbquery

package
v0.0.1-beta.21 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultPageSize = 20
)

Variables

This section is empty.

Functions

func WithBuildDefaultSorter

func WithBuildDefaultSorter(enabled bool) func(*buildOption)

WithBuildDefaultSorter 是否启用默认ID倒序排序。默认启用

func WithBuildLimitPage

func WithBuildLimitPage(start, limit, maxLimit int) func(*buildOption)

WithBuildLimitPage 限制最大条数的分页参数

func WithBuildPage

func WithBuildPage(start, limit int) func(*buildOption)

WithBuildPage 分页参数,默认最大 limit 不超过100

func WithBuildSortField

func WithBuildSortField(field string, other ...string) func(*buildOption)

WithBuildSortField 指定启用排序的数据库字段。需保证和数据库中字段一致

func WithBuildSortKeyMappings

func WithBuildSortKeyMappings(mapping map[string]string) func(*buildOption)

WithBuildSortKeyMappings 指定前端排序字段和数据库字段的映射关系。

func WithPreloads

func WithPreloads(preload string, others ...string) func(*option)

WithPreloads gorm Preload

func WithSorts

func WithSorts(sort string) func(*option)

WithSorts 排序规则 以符号开头,可选符号:(+或空 正序)(- 倒序)(* 自定义复杂排序标识关键词) 多个排序规则按英文逗号隔开

Types

type IPager

type IPager[T any] interface {
	Filter() *T
	Sorters() []Sorter

	Preloads() []string

	BuildDB(db *gorm.DB, opts ...func(*buildOption)) *gorm.DB
	String() string
}

IPager 分页参数

func New

func New[T any](filter *T, opts ...func(*option)) IPager[T]

type Sorted

type Sorted uint8

Sorted 排序顺序

const (
	ASC    Sorted = iota // 正序
	DESC                 // 倒序
	Custom               // 自定义
)

func (Sorted) String

func (s Sorted) String() string

type Sorter

type Sorter struct {
	Field  string
	Sorted Sorted
}

Sorter 排序器

Jump to

Keyboard shortcuts

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