mysql

package
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var MysqlDefaultConfigs = make(MysqlConfigs_T, 1)

Functions

func Client

func Client() (*sqlx.DB, error)

获取连接

func Close

func Close()

func Connect

func Connect(config MysqlConfig_T) error

func GetClient

func GetClient(origin string) (*sqlx.DB, error)

func Init

func Init(cfgs MysqlConfigs_T) error

func LoadDefaultConfig

func LoadDefaultConfig() error

Types

type MysqlConfig_T

type MysqlConfig_T struct {
	Tag string `json:"tag"`
	// timeout=5s	连接超时时间
	// readTimeout=10s	读取超时
	// writeTimeout=10s	写入超时
	// charset=utf8mb4	字符集(支持emoji)
	// loc=Local	使用本地时区
	// interpolateParams=true	预处理语句优化(可能提升性能)
	// "username:password@tcp(127.0.0.1:3306)/dbname?charset=utf8mb4&timeout=10s&readTimeout=30s&writeTimeout=30s&parseTime=true&loc=Local"
	Addr               string        `json:"addr"`
	MaxOpenConns       int           `json:"maxOpenConns"`       // 设置最大打开连接数
	MaxIdleConns       int           `json:"maxIdleConns"`       // 设置最大空闲连接数
	ConnMaxLifetime    time.Duration `json:"-"`                  // 设置连接的最大生命周期 单位s
	ConnMaxLifetimeInt int           `json:"connMaxLifetimeInt"` // 设置连接的最大存活时间 单位s
}

type MysqlConfigs_T

type MysqlConfigs_T map[string]MysqlConfig_T

Jump to

Keyboard shortcuts

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