mysql

package
v0.0.0-...-6f9dc6e Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultMaxOpenConn        = 1000
	DefaultMaxIdleConn        = 100
	DefaultConnMaxLifeSecond  = 30 * time.Minute
	DefaultLogName            = "gorm"
	DefaultSlowLogMillisecond = 200 // 慢查日志
	DefaultClient             = "default-mysql-client"
	ReadClient                = "read-mysql"
	WriteClient               = "write-mysql"
	TxClient                  = "tx-mysql"
)

Variables

View Source
var (
	StdLogger stdLogger
)

Functions

func CloseMysqlClient

func CloseMysqlClient(clientName string) error

func InitMysqlClient

func InitMysqlClient(clientName, username, password, host, port, dbName string, options ...Option) error

Types

type Config

type Config struct {
	MaxOpenConn        int
	MaxIdleConn        int
	ConnMaxLifeSecond  time.Duration
	MaxIdleTime        time.Duration
	PrepareStmt        bool
	LogName            string
	SlowLogMillisecond int64
	EnableSqlLog       bool
	Logger             Logger
}

func NewDefaultOption

func NewDefaultOption() *Config

NewDefaultOption 创建默认配置项

func (*Config) Reset

func (o *Config) Reset()

Reset reset Default config

type DB

type DB struct {
	*gorm.DB
	ClientName string
	Username   string

	Host   string
	DBName string
	// contains filtered or unexported fields
}

func GetMysqlClient

func GetMysqlClient(clientName string) *DB

type Logger

type Logger logger.Interface

type LoggerConfig

type LoggerConfig logger.Config

func NewDefaultLoggerConf

func NewDefaultLoggerConf() LoggerConfig

NewDefaultLoggerConf 创建日志默认配置

type Option

type Option func(*Config)

func WithConnMaxLifeSecond

func WithConnMaxLifeSecond(connMaxLifeTime time.Duration) Option

func WithEnableSqlLog

func WithEnableSqlLog(enableSqlLog bool) Option

func WithLogName

func WithLogName(logName string) Option

func WithLogger

func WithLogger(writer io.Writer, config LoggerConfig) Option

func WithMaxIdleConn

func WithMaxIdleConn(maxIdleConn int) Option

func WithMaxIdleTime

func WithMaxIdleTime(MaxIdleTime time.Duration) Option

func WithMaxOpenConn

func WithMaxOpenConn(maxOpenConn int) Option

func WithPrepareStmt

func WithPrepareStmt(prepareStmt bool) Option

func WithSlowLogMillisecond

func WithSlowLogMillisecond(slowLogMillisecond int64) Option

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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