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.
|
|
package initialize
import ( "github.com/flipped-aurora/gin-vue-admin/server/global" "github.com/flipped-aurora/gin-vue-admin/server/initialize/internal" "gorm.io/driver/postgres" "gorm.io/gorm" )
// GormPgSql 初始化 Postgresql 数据库
// Author [piexlmax](https://github.com/piexlmax)
// Author [SliverHorn](https://github.com/SliverHorn)
func GormPgSql() *gorm.DB { p := global.GVA_CONFIG.Pgsql if p.Dbname == "" { return nil } pgsqlConfig := postgres.Config{ DSN: p.Dsn(), // DSN data source name
PreferSimpleProtocol: false, } if db, err := gorm.Open(postgres.New(pgsqlConfig), internal.Gorm.Config()); err != nil { return nil } else { sqlDB, _ := db.DB() sqlDB.SetMaxIdleConns(p.MaxIdleConns) sqlDB.SetMaxOpenConns(p.MaxOpenConns) return db } }
|