database

package
v0.0.30 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2024 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrorsGormDBCreateParamsNotPtr string = "gorm Create 函数的参数必须是一个指针, 为了完美支持 gorm 的所有回调函数,请在参数前面添加 & "
	ErrorsGormDBUpdateParamsNotPtr string = "" /* 179-byte string literal not displayed */
)

Variables

This section is empty.

Functions

func CloseDB

func CloseDB()

func CreateBeforeHook

func CreateBeforeHook(gormDB *gorm.DB)

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

func DB

func DB() *gorm.DB

func Init

func Init()

func InitDB

func InitDB() *gorm.DB

func MaskNotDataError

func MaskNotDataError(gormDB *gorm.DB)

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

func UpdateBeforeHook

func UpdateBeforeHook(gormDB *gorm.DB)

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

func UpdateCreatedTimeHook

func UpdateCreatedTimeHook(db *gorm.DB)

func UpdateDeletedTimeHook

func UpdateDeletedTimeHook(db *gorm.DB)

func UpdateIdHook

func UpdateIdHook(db *gorm.DB)

func UpdateLastModifiedTimeHook

func UpdateLastModifiedTimeHook(db *gorm.DB)

Types

type LoggerWrapper

type LoggerWrapper struct {
	gormLog.Writer
	gormLog.Config
	// contains filtered or unexported fields
}

func (*LoggerWrapper) Error

func (l *LoggerWrapper) Error(_ context.Context, msg string, data ...interface{})

Error print error messages

func (*LoggerWrapper) Info

func (l *LoggerWrapper) Info(_ context.Context, msg string, data ...interface{})

Info print info

func (*LoggerWrapper) LogMode

func (l *LoggerWrapper) LogMode(level gormLog.LogLevel) gormLog.Interface

LogMode log mode

func (*LoggerWrapper) Trace

func (l *LoggerWrapper) Trace(ctx context.Context, begin time.Time, fc func() (string, int64), err error)

Trace print sql message

func (*LoggerWrapper) Warn

func (l *LoggerWrapper) Warn(_ context.Context, msg string, data ...interface{})

Warn print warn messages

type MyNamingStrategy

type MyNamingStrategy struct {
	schema.NamingStrategy
}

func (MyNamingStrategy) JoinTableName

func (ns MyNamingStrategy) JoinTableName(str string) string

func (MyNamingStrategy) TableName

func (ns MyNamingStrategy) TableName(str string) string

type OptionFunc

type OptionFunc func(log *LoggerWrapper)

type Options

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

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

func SetErrStrFormat

func SetErrStrFormat(format string) Options

func SetInfoStrFormat

func SetInfoStrFormat(format string) Options

定义 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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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