go-wxhelper/client/mysql.go
李寻欢 8f15b58825
All checks were successful
BuildImage / build-image (push) Successful in 1m9s
🎨 逻辑修改,把依赖从写死改为配置
2023-10-26 10:07:08 +08:00

28 lines
611 B
Go

package client
import (
"go-wechat/config"
"gorm.io/driver/mysql"
"gorm.io/gorm"
"log"
)
// MySQL客户端
var MySQL *gorm.DB
func InitMySQLClient() {
// 创建连接对象
mysqlConfig := mysql.Config{
DSN: config.Conf.MySQL.GetDSN(),
DontSupportRenameIndex: true, // 重命名索引时采用删除并新建的方式
DontSupportRenameColumn: true, // 用 `change` 重命名列
}
conn, err := gorm.Open(mysql.New(mysqlConfig))
if err != nil {
log.Panicf("初始化MySQL连接失败, 错误信息: %v", err)
} else {
log.Println("MySQL连接成功")
}
MySQL = conn
}