1234567891011121314151617181920212223242526272829303132333435 |
- package global
- import (
- "Panel_development/configs"
- "fmt"
- "gorm.io/driver/mysql"
- "gorm.io/gorm"
- "gorm.io/gorm/logger"
- )
- var (
- DBLink *gorm.DB
- )
- func SetupDBLink() error {
- var err error
- dsn := fmt.Sprintf("%s:%s@tcp(%s)/%s?%s",
- configs.Config.GetString("database.userName"),
- configs.Config.GetString("database.password"),
- configs.Config.GetString("database.host"),
- configs.Config.GetString("database.db"),
- configs.Config.GetString("database.otherParams"),
- )
- DBLink, err = gorm.Open(mysql.Open(dsn), &gorm.Config{
- DisableForeignKeyConstraintWhenMigrating: true,
- Logger: logger.Default.LogMode(logger.Info),
- })
- if err != nil {
- return err
- }
- //DBLink.SingularTable(true)
- //DBLink.DB().SetMaxIdleConns(DatabaseSetting.MaxIdleConn)
- //DBLink.DB().SetMaxOpenConns(DatabaseSetting.MaxOpenConn)
- return nil
- }
|