util

package
v0.0.0-...-c8dbcfe Latest Latest
Warning

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

Go to latest
Published: May 31, 2023 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), "*"))

Functions

func Check

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

func ExecTrans

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

func ExecTransWithLock

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

func FindOne

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

func FindPage

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

func GetDB

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

Get gorm.DB from context

func GetDBWithModel

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

Get gorm.DB.Model from context

func ParseOrder

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

func WrapPageQuery

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

Types

type Model

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

Define base model

type OrderFieldFunc

type OrderFieldFunc func(string) string

Define order fields convert function

type Trans

type Trans struct {
	DB *gorm.DB
}

func (*Trans) Exec

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

type TransFunc

type TransFunc func(context.Context) error

Define transaction execute function

Jump to

Keyboard shortcuts

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