Skip to content

Commit

Permalink
feat: remove resolver
Browse files Browse the repository at this point in the history
  • Loading branch information
sujit-baniya committed Aug 1, 2023
1 parent a492af2 commit ba429ec
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions database/gorm.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"gorm.io/driver/sqlserver"
"gorm.io/gorm"
glog "gorm.io/gorm/logger"
"gorm.io/plugin/dbresolver"

"github.com/oarkflow/framework/contracts/database/orm"
"github.com/oarkflow/framework/database/support"
Expand Down Expand Up @@ -49,16 +48,17 @@ func NewGormDB(ctx context.Context, connection string, config *gorm.Config, disa
if maxIdleConnections == 0 {
maxIdleConnections = int(float64(maxOpenConnections) - (20 / float64(maxOpenConnections) * 100))
}
resolver := dbresolver.Register(dbresolver.Config{})
sqlDB, err := db.DB()
if err != nil {
return nil, err
}
sqlDB.SetMaxIdleConns(maxIdleConnections)
sqlDB.SetMaxOpenConns(maxOpenConnections)
if maxIdleTime > 0 {
resolver = resolver.SetConnMaxIdleTime(time.Duration(maxIdleTime) * time.Minute)
sqlDB.SetConnMaxIdleTime(time.Duration(maxIdleTime) * time.Minute)
}
if maxLifeTime > 0 {
resolver = resolver.SetConnMaxLifetime(time.Duration(maxLifeTime) * time.Hour)
}
err = db.Use(resolver.SetMaxIdleConns(maxIdleConnections).SetMaxOpenConns(maxOpenConnections))
if err != nil {
return nil, err
sqlDB.SetConnMaxLifetime(time.Duration(maxLifeTime) * time.Hour)
}
}
return &GormDB{
Expand Down

0 comments on commit ba429ec

Please sign in to comment.