dao

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2023 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetPageList

func GetPageList[T any](page *PageRequest, model *gorm.DB, list *response.PageList[T]) (err error)

GetPageList 分页公共方法

func Paginate

func Paginate(p *PageRequest) func(db *gorm.DB) *gorm.DB

Types

type PageRequest

type PageRequest struct {
	Page     int                    // 页码
	PageSize int                    // 每页数量
	Total    int64                  // total 总数
	Where    map[string]interface{} // 条件and 自行拼接
	OrWhere  map[string]interface{} // 条件or 自行拼接
	// contains filtered or unexported fields
}

PageRequest 分页请求的参数

func NewPageReq

func NewPageReq() *PageRequest

NewPageReq 初始化分页请求参数 默认第一页 每页10条

func (*PageRequest) AscSort

func (p *PageRequest) AscSort(field string)

AscSort 正序排序 多个排序字段使用空格隔开

func (*PageRequest) DescSort

func (p *PageRequest) DescSort(field string)

DescSort 倒序排序 多个排序字段使用空格隔开

type Util added in v0.1.5

type Util[T interface{}] struct {
	DB                *gorm.DB
	Model             *T
	PageRequestParams *PageRequest
}

func NewUtil added in v0.1.5

func NewUtil[T interface{}](db *gorm.DB) *Util[T]

func (*Util[T]) CreateMany added in v0.1.5

func (u *Util[T]) CreateMany(model *[]T) error

CreateMany 创建多条记录

func (*Util[T]) CreateOne added in v0.1.5

func (u *Util[T]) CreateOne(model *T) error

CreateOne 创建一条记录

func (*Util[T]) DeleteMany added in v0.1.5

func (u *Util[T]) DeleteMany(model *[]T) error

DeleteMany 删除多条记录

func (*Util[T]) DeleteOne added in v0.1.5

func (u *Util[T]) DeleteOne(model *T) error

DeleteOne 删除一条记录

func (*Util[T]) GetAll added in v0.1.5

func (u *Util[T]) GetAll() ([]T, error)

GetAll 获取所有记录

func (*Util[T]) GetDB added in v0.1.7

func (u *Util[T]) GetDB() *gorm.DB

GetDB 获取DB

func (*Util[T]) GetList added in v0.1.5

func (u *Util[T]) GetList(request *PageRequest) (*response.PageList[T], error)

GetList 获取多条记录

func (*Util[T]) GetListWithData added in v0.1.8

func (u *Util[T]) GetListWithData(request *PageRequest, data interface{}) (*response.PageList[T], error)

GetListWithData 获取多条记录 使用传入的data进行返回赋值 , 第二个参数需要传入指针

func (*Util[T]) GetOne added in v0.1.5

func (u *Util[T]) GetOne(model *T) error

GetOne 获取一条记录

func (*Util[T]) SetDB added in v0.1.6

func (u *Util[T]) SetDB(fn func(db *gorm.DB) *gorm.DB)

SetDB 修改DB

func (*Util[T]) UpdateMany added in v0.1.5

func (u *Util[T]) UpdateMany(model *[]T) error

UpdateMany 更新多条记录

func (*Util[T]) UpdateOne added in v0.1.5

func (u *Util[T]) UpdateOne(model *T) error

UpdateOne 更新一条记录

func (*Util[T]) UpdateOneColumn added in v0.1.7

func (u *Util[T]) UpdateOneColumn(model *T, column ...string) error

UpdateOneColumn 根据字段名更新单列

Jump to

Keyboard shortcuts

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