You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1Panel/backend/init/db/mysql.go

29 lines
555 B

package db
import (
"github.com/1Panel-dev/1Panel/global"
"gorm.io/driver/mysql"
"gorm.io/gorm"
)
func MysqlGorm() *gorm.DB {
m := global.CONF.Mysql
if m.Dbname == "" {
return nil
}
mysqlConfig := mysql.Config{
DSN: m.Dsn(),
DefaultStringSize: 191,
SkipInitializeWithVersion: false,
}
if db, err := gorm.Open(mysql.New(mysqlConfig), &gorm.Config{}); err != nil {
panic(err)
} else {
sqlDB, _ := db.DB()
sqlDB.SetMaxIdleConns(m.MaxIdleConns)
sqlDB.SetMaxOpenConns(m.MaxOpenConns)
return db
}
}