mirror of
https://github.com/flipped-aurora/gin-vue-admin.git
synced 2026-09-21 20:35:16 +00:00
增加pgsql适配(todo)
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
package initialize
|
||||
|
||||
import (
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/global"
|
||||
"gorm.io/driver/postgres"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
//@author: SliverHorn
|
||||
//@function: GormMysql
|
||||
//@description: 初始化Mysql数据库
|
||||
//@return: *gorm.DB
|
||||
|
||||
func GormPgSql() *gorm.DB {
|
||||
p := global.GVA_CONFIG.Pgsql
|
||||
if p.Dbname == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
dsn := "host=" + p.Path + " user=" + p.Username + " password=" + p.Password + " dbname=" + p.Dbname + " port=" + p.Port + " " + p.Config
|
||||
pgsqlConfig := postgres.Config{
|
||||
DSN: dsn, // DSN data source name
|
||||
PreferSimpleProtocol: false,
|
||||
}
|
||||
if db, err := gorm.Open(postgres.New(pgsqlConfig), gormConfig()); err != nil {
|
||||
//global.GVA_LOG.Error("MySQL启动异常", zap.Any("err", err))
|
||||
//os.Exit(0)
|
||||
//return nil
|
||||
return nil
|
||||
} else {
|
||||
sqlDB, _ := db.DB()
|
||||
sqlDB.SetMaxIdleConns(p.MaxIdleConns)
|
||||
sqlDB.SetMaxOpenConns(p.MaxOpenConns)
|
||||
return db
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user