gormx

package
v0.3.6 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2024 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateBeforeHook

func CreateBeforeHook(gormDB *gorm.DB)

CreateBeforeHook InterceptCreatePramsNotPtrError 拦截 create 函数参数如果是非指针类型的错误,新用户最容犯此错误

func GetSqlDriver

func GetSqlDriver(conf Conf) (*gorm.DB, error)

func MaskNotDataError

func MaskNotDataError(gormDB *gorm.DB)

MaskNotDataError 解决gorm v2 包在查询无数据时,报错问题(record not found),但是官方认为报错是应该是,我们认为查询无数据,代码一切ok,不应该报错

func Paginate

func Paginate(page int, pageSize int) func(db *gorm.DB) *gorm.DB

Paginate 分页封装

func UpdateBeforeHook

func UpdateBeforeHook(gormDB *gorm.DB)

UpdateBeforeHook InterceptUpdatePramsNotPtrError 拦截 save、update 函数参数如果是非指针类型的错误 对于开发者来说,以结构体形式更新数,只需要在 update 、save 函数的参数前面添加 & 即可 最终就可以完美兼支持、兼容 gorm 的所有回调函数 但是如果是指定字段更新,例如: UpdateColumn 函数则只传递值即可,不需要做校验

Types

type Base

type Base struct {
	Id        int64     `gorm:"primaryKey" json:"id"`
	CreatedAt time.Time `gorm:"created_at" json:"createdAt"`
	UpdatedAt time.Time `gorm:"updated_at" json:"updatedAt"`
}

type BaseDel

type BaseDel struct {
	Id        int64                 `gorm:"primaryKey" json:"id"`
	CreatedAt time.Time             `gorm:"created_at" json:"createdAt"`
	UpdatedAt time.Time             `gorm:"updated_at" json:"updatedAt"`
	DeletedAt soft_delete.DeletedAt `gorm:"delete_at" json:"-"`
}

type Client

type Client struct {
	Conf   Conf
	GormDb *gorm.DB
}

func MustNewClient

func MustNewClient(conf Conf) *Client

func NewClient

func NewClient(conf Conf) (*Client, error)

type Conf

type Conf struct {
	SqlType       SqlTypeEnum
	SlowThreshold int
	IsOpenReadDb  bool
	Write         ConfigParamsDetail
	Read          ConfigParamsDetail
}

type ConfigParamsDetail

type ConfigParamsDetail struct {
	Host               string
	DataBase           string
	Port               int
	Prefix             string
	User               string
	Pass               string
	Charset            string
	SetMaxIdleConn     int
	SetMaxOpenConn     int
	SetConnMaxLifetime int
}

type GormCache added in v0.3.6

type GormCache struct {
	Cache cache.Cache
	Db    *gorm.DB
	Conf  cache.CacheConf
}

func NewCacheTool

func NewCacheTool(conf cache.CacheConf, db *gorm.DB) *GormCache

type OptionFunc

type OptionFunc func(log *logger)

type Options

type Options interface {
	// contains filtered or unexported methods
}

Options 尝试从外部重写内部相关的格式化变量

func SetErrStrFormat

func SetErrStrFormat(format string) Options

func SetInfoStrFormat

func SetInfoStrFormat(format string) Options

SetInfoStrFormat 定义 6 个函数修改内部变量

func SetTracErrStrFormat

func SetTracErrStrFormat(format string) Options

func SetTracWarnStrFormat

func SetTracWarnStrFormat(format string) Options

func SetTraceStrFormat

func SetTraceStrFormat(format string) Options

func SetWarnStrFormat

func SetWarnStrFormat(format string) Options

type SqlTypeEnum

type SqlTypeEnum int
const (
	MysqlType SqlTypeEnum = iota
	PostgresqlType
	SqlServerType
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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