util

package
v0.0.0-...-364eef1 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var TransSet = wire.NewSet(wire.Struct(new(Trans), "*"))

TransSet 注入Trans

Functions

func Check

func Check(ctx context.Context, db *gorm.DB) (bool, error)

Check 检查数据是否存在

func ExecTrans

func ExecTrans(ctx context.Context, db *gorm.DB, fn TransFunc) error

ExecTrans 执行事务

func ExecTransWithLock

func ExecTransWithLock(ctx context.Context, db *gorm.DB, fn TransFunc) error

ExecTransWithLock 执行事务(加锁)

func FindOne

func FindOne(ctx context.Context, db *gorm.DB, out interface{}) (bool, error)

FindOne 查询单条数据

func FindPage

func FindPage(ctx context.Context, db *gorm.DB, pp schema.PaginationParam, out interface{}) (int64, error)

FindPage 查询分页数据

func GetDB

func GetDB(ctx context.Context, defDB *gorm.DB) *gorm.DB

GetDB Get gorm.DB from context

func GetDBWithModel

func GetDBWithModel(ctx context.Context, defDB *gorm.DB, m interface{}) *gorm.DB

GetDBWithModel Get gorm.DB.Model from context

func ParseOrder

func ParseOrder(items []*schema.OrderField, handle ...OrderFieldFunc) string

ParseOrder 解析排序字段

func WrapPageQuery

func WrapPageQuery(ctx context.Context, db *gorm.DB, pp schema.PaginationParam, out interface{}) (*schema.PaginationResult, error)

WrapPageQuery 包装带有分页的查询

Types

type Model

type Model struct {
	ID        uint64 `gorm:"primaryKey;"`
	CreatedAt time.Time
	UpdatedAt time.Time
}

Model Define basic

type OrderFieldFunc

type OrderFieldFunc func(string) string

OrderFieldFunc 排序字段转换函数

type Trans

type Trans struct {
	DB *gorm.DB
}

Trans 事务管理

func (*Trans) Exec

func (a *Trans) Exec(ctx context.Context, fn func(context.Context) error) error

Exec 执行事务

type TransFunc

type TransFunc func(context.Context) error

TransFunc 定义事务执行函数

Jump to

Keyboard shortcuts

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