gormlib

package
v1.1.97 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitDB added in v1.1.7

func InitDB(name string, dsn string) (*gorm.DB, error)

InitDB 初始化数据库, 必须先初始化logger库

func MicrosecondsStr added in v1.1.20

func MicrosecondsStr(elapsed time.Duration) string

MicrosecondsStr 将 time.Duration 类型(nano seconds 为单位) 输出为小数点后 3 位的 ms (microsecond 毫秒,千分之一秒)

Types

type GormLogger added in v1.1.20

type GormLogger struct {
	ZapLogger     *zap.Logger
	SlowThreshold time.Duration
}

GormLogger 操作对象,实现 gormlogger.Interface

func NewGormLogger added in v1.1.20

func NewGormLogger() GormLogger

NewGormLogger 外部调用。实例化一个 GormLogger 对象,示例:

DB, err := gorm.Open(dbConfig, &gorm.Config{
    Logger: logger.NewGormLogger(),
})

func (GormLogger) Error added in v1.1.20

func (l GormLogger) Error(ctx context.Context, str string, args ...interface{})

Error 实现 gormlogger.Interface 的 Error 方法

func (GormLogger) Info added in v1.1.20

func (l GormLogger) Info(ctx context.Context, str string, args ...interface{})

Info 实现 gormlogger.Interface 的 Info 方法

func (GormLogger) LogMode added in v1.1.20

LogMode 实现 gormlogger.Interface 的 LogMode 方法

func (GormLogger) Trace added in v1.1.20

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

Trace 实现 gormlogger.Interface 的 Trace 方法

func (GormLogger) Warn added in v1.1.20

func (l GormLogger) Warn(ctx context.Context, str string, args ...interface{})

Warn 实现 gormlogger.Interface 的 Warn 方法

type TimeBase added in v1.1.21

type TimeBase struct {
	CreatedAt timelib.JsonTime  `gorm:"type:timestamp NULL;default:NULL;index" json:"created_at"`
	UpdatedAt timelib.JsonTime  `gorm:"type:timestamp NULL;default:NULL" json:"updated_at"`
	DeletedAt *timelib.JsonTime `gorm:"type:timestamp NULL;default:NULL;index" json:"-"`
}

TimeBase TimeBase

Jump to

Keyboard shortcuts

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