gorm

package
v0.0.0-...-b804f52 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2023 License: MulanPSL-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Build

func Build(name string) *gorm.DB

func NewLogger

func NewLogger(level gormlogger.LogLevel, slowThreshold time.Duration) gormlogger.Interface

func OpenMysql

func OpenMysql(dbConfig *Config) (*gorm.DB, error)

Open ...

func UnmarshalText

func UnmarshalText(text string) gormlogger.LogLevel

Types

type Config

type Config struct {
	Name string
	// DSN地址: mysql://root:secret@tcp(127.0.0.1:3307)/mysql?timeout=20s&readTimeout=20s
	DSN         string
	DSNReplicas []string
	// Debug开关
	LogLevel string
	// 最大空闲连接数
	MaxIdleConns int
	// 最大活动连接数
	MaxOpenConns int
	// 连接的最大存活时间
	ConnMaxLifetime time.Duration
	// 慢日志阈值
	SlowThreshold time.Duration
	// 生成 SQL 但不执行
	DryRun bool
	// 跳过默认事务
	SkipDefaultTransaction bool
}

config options

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig 返回默认配置

type Logger

type Logger struct {
	LogLevel      gormlogger.LogLevel
	SlowThreshold time.Duration
}

func (Logger) Error

func (l Logger) Error(_ context.Context, str string, args ...interface{})

func (Logger) Info

func (l Logger) Info(_ context.Context, str string, args ...interface{})

func (*Logger) LogMode

func (l *Logger) LogMode(level gormlogger.LogLevel) gormlogger.Interface

func (Logger) Trace

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

func (Logger) Warn

func (l Logger) Warn(_ context.Context, str string, args ...interface{})

Jump to

Keyboard shortcuts

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