代码拉取完成,页面将自动刷新
package database
import (
toolsConfig "gitee.com/sansaniot/ssiot-core/config"
"gitee.com/sansaniot/ssiot-core/facade/runtime"
log "gitee.com/sansaniot/ssiot-core/logger"
"gitee.com/sansaniot/ssiot-core/storage/database/dbconfig"
gormLogger "gitee.com/sansaniot/ssiot-core/storage/database/gorm/logger"
"gitee.com/sansaniot/ssiot-core/utils"
"gorm.io/gorm"
"gorm.io/gorm/logger"
"gorm.io/gorm/schema"
"time"
)
func SetupDatabase(host string, c *toolsConfig.Database) {
log.Infof("%s => %s", host, utils.Green(c.Source))
registers := make([]dbconfig.ResolverConfigure, len(c.Registers))
for i := range c.Registers {
registers[i] = dbconfig.NewResolverConfigure(
c.Registers[i].Sources,
c.Registers[i].Replicas,
c.Registers[i].Policy,
c.Registers[i].Tables)
}
resolverConfig := dbconfig.NewConfigure(c.Source, c.MaxIdleConns, c.MaxOpenConns, c.ConnMaxIdleTime, c.ConnMaxLifeTime, registers)
db, err := resolverConfig.Init(&gorm.Config{
NamingStrategy: schema.NamingStrategy{
SingularTable: true,
},
Logger: gormLogger.New(
logger.Config{
SlowThreshold: time.Second,
Colorful: true,
LogLevel: logger.LogLevel(
log.DefaultLogger.Options().Level.LevelForGorm()),
},
),
}, opens[c.Driver])
if err != nil {
log.Fatal(utils.Red(c.Driver+" connect error :"), err)
} else {
log.Info(utils.Green(c.Driver + " connect success !"))
}
runtime.Runtime.SetDb(host, db)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。