reload时close db

This commit is contained in:
xing 2023-04-11 13:11:21 +08:00
parent 0d8ee89580
commit db49f99c04

View File

@ -19,6 +19,10 @@ func InitDb() (*safety.Var[*sqlx.DB], error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
preDb := safeDb.Load()
if preDb != nil {
_ = preDb.Close()
}
if c.Mysql.Pool.ConnMaxIdleTime != 0 { if c.Mysql.Pool.ConnMaxIdleTime != 0 {
db.SetConnMaxIdleTime(c.Mysql.Pool.ConnMaxLifetime) db.SetConnMaxIdleTime(c.Mysql.Pool.ConnMaxLifetime)
} }