Zeus/helper/gorm_helper.go

17 lines
371 B
Go
Raw Normal View History

2021-12-14 13:53:22 +08:00
package bgm
2021-12-13 21:39:15 +08:00
import (
2021-12-14 14:31:18 +08:00
"bgm/consts"
2021-12-14 13:53:22 +08:00
"fmt"
2021-12-13 21:39:15 +08:00
"gorm.io/driver/mysql"
"gorm.io/gorm"
)
2021-12-14 14:31:18 +08:00
type MysqlMap map[string]*gorm.DB
func GormMap(dsnPre string) (MysqlMap, error) {
dsn := fmt.Sprintf("%v/%v?charset=utf8mb4&parseTime=True&loc=Local", dsnPre, consts.TestDB)
2021-12-13 21:39:15 +08:00
db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{})
2021-12-14 14:31:18 +08:00
return map[string]*gorm.DB{consts.TestDB: db}, err
2021-12-13 21:39:15 +08:00
}