Help us shape the future of Go! Take the 2026 Go Developer Survey

base

package
v0.6.3 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2026 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildArray

func BuildArray[T any](data []T) []any

构建interface数组

func Page

func Page[R any, T any](ctx context.Context, db *gorm.DB, t *T, query SearchCriteria) (data []*R, total int64, err error)

封装分页列表查询操作

Types

type Entity

type Entity struct {
	ID        uuid.UUID      `gorm:"type:uuid;default:gen_random_uuid();comment:主键"`
	CreatedAt time.Time      `gorm:"comment:创建时间"`
	UpdatedAt time.Time      `gorm:"comment:更新时间"`
	DeletedAt gorm.DeletedAt `gorm:"index;comment:删除时间"`
}

type FuzzyField

type FuzzyField struct {
	Name  string `json:"name"`  //查询字段名称
	Value any    `json:"value"` //查询字段值
}

type GTEField

type GTEField struct {
	Name  string  `json:"name"`
	Value float64 `json:"value"`
}

type GTField

type GTField struct {
	Name  string  `json:"name"`
	Value float64 `json:"value"`
}

type JSONField

type JSONField struct {
	TermFields  []JSONTermField
	FuzzyFields []JSONFuzzyField
	LTEFields   []JSONLTEField
	LTFields    []JSONLTField
	GTEFields   []JSONGTEField
	GTFields    []JSONGTField
	ArrayFields []TermField
}

type JSONFuzzyField

type JSONFuzzyField struct {
	Field string `json:"field"` //json字段名
	Name  string `json:"name"`  //查询字段名称
	Value any    `json:"value"` //查询字段值
}

type JSONGTEField

type JSONGTEField struct {
	Field string  `json:"field"` //json字段名
	Name  string  `json:"name"`
	Value float64 `json:"value"`
}

type JSONGTField

type JSONGTField struct {
	Field string  `json:"field"` //json字段名
	Name  string  `json:"name"`
	Value float64 `json:"value"`
}

type JSONLTEField

type JSONLTEField struct {
	Field string  `json:"field"` //json字段名
	Name  string  `json:"name"`
	Value float64 `json:"value"`
}

type JSONLTField

type JSONLTField struct {
	Field string  `json:"field"` //json字段名
	Name  string  `json:"name"`
	Value float64 `json:"value"`
}

type JSONTermField

type JSONTermField struct {
	Field string `json:"field"` //json字段名
	Name  string `json:"name"`  //查询字段名称
	Value []any  `json:"value"` //查询字段值
}

type LTEField

type LTEField struct {
	Name  string  `json:"name"`
	Value float64 `json:"value"`
}

type LTField

type LTField struct {
	Name  string  `json:"name"`
	Value float64 `json:"value"`
}

type Model added in v0.1.1

type Model struct {
	ID        int64          `gorm:"primaryKey;autoIncrement:false;comment:主键"`
	CreatedAt time.Time      `gorm:"comment:创建时间"`
	UpdatedAt time.Time      `gorm:"comment:更新时间"`
	DeletedAt gorm.DeletedAt `gorm:"index;comment:删除时间"`
}

type NotNullField added in v0.0.9

type NotNullField struct {
	Name string `json:"name"` //查询字段名称
}

type OrFuzzyField

type OrFuzzyField struct {
	Names []string `json:"names"` //查询字段名称
	Value any      `json:"value"` //查询字段值
}

type PageQuery

type PageQuery struct {
	Page  int `form:"page"`  //页数
	Limit int `form:"limit"` //每页个数
}

func (*PageQuery) InjectDefault

func (pq *PageQuery) InjectDefault()

func (*PageQuery) Offset

func (pq *PageQuery) Offset() int

type PreloadField added in v0.3.3

type PreloadField struct {
	Name string
	Args []any
}

type RawSearchCriteria

type RawSearchCriteria struct {
	SelectSql string
	CountSql  string
	Where     []string
	OrderSql  string
	Values    []any
	PageQuery
}

RawSearchCriteria 原生查询

type SearchCriteria

type SearchCriteria struct {
	PageQuery
	Columns string
	Table   string
	SearchField
	Preloads       []PreloadField
	Joins          []string
	Order          string
	Group          string
	OrFuzzys       []OrFuzzyField
	NoPageQuery    bool
	ContainsDelete bool
}

SearchCriteria 搜索条件

func NewJoinSearchCriteria

func NewJoinSearchCriteria(columns, table string, joins []string) *SearchCriteria

func NewJoinSearchCriteriaOfPageQuery

func NewJoinSearchCriteriaOfPageQuery(query PageQuery, columns, table string, joins []string) *SearchCriteria

func NewSearchCriteriaOfPageQuery

func NewSearchCriteriaOfPageQuery(query PageQuery) *SearchCriteria

func (*SearchCriteria) BuildDB

func (sc *SearchCriteria) BuildDB(db *gorm.DB) *gorm.DB

func (*SearchCriteria) WithKeyword

func (sc *SearchCriteria) WithKeyword(names []string, keyword string) *SearchCriteria

关键词查询

type SearchField

type SearchField struct {
	TermFields    []TermField
	FuzzyFields   []FuzzyField
	LTEFields     []LTEField
	LTFields      []LTField
	GTEFields     []GTEField
	GTFields      []GTField
	JSONField     JSONField
	NotMullFields []NotNullField
}

type TermField

type TermField struct {
	Name  string `json:"name"`  //查询字段名称
	Value []any  `json:"value"` //查询字段值
}

Jump to

Keyboard shortcuts

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