db

package module
v0.0.0-...-e621d65 Latest Latest
Warning

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

Go to latest
Published: May 3, 2026 License: MIT Imports: 9 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-msql"
	TxClient                  = "tx-mysql"
)

Variables

View Source
var (
	MysqlClients   = make(map[string]*DB)
	MysqlStdLogger stdLogger
)

Functions

func CloseMysqlClient

func CloseMysqlClient(clientName string) error

func InitMysqlClient

func InitMysqlClient(clientName, username, password, host, dbName string) error

func InitMysqlClientWithOptions

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

Types

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 Option

type Option func(*option)

func WithConnMaxLifeSecond

func WithConnMaxLifeSecond(connMaxLifeTime time.Duration) Option

func WithEnableSqlLog

func WithEnableSqlLog(enableSqlLog bool) Option

func WithLogName

func WithLogName(logName string) Option

func WithMaxIdleConn

func WithMaxIdleConn(maxIdleConn int) Option

func WithMaxOpenConn

func WithMaxOpenConn(maxOpenConn int) Option

func WithPrepareStmt

func WithPrepareStmt(prepareStmt bool) Option

func WithSlowLogMillSecond

func WithSlowLogMillSecond(slowLogMillSecond int64) Option

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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