diff --git a/starter/gorm/autoconfigure.go b/starter/gorm/autoconfigure.go index 92ecdb6..fe8ec42 100644 --- a/starter/gorm/autoconfigure.go +++ b/starter/gorm/autoconfigure.go @@ -90,8 +90,8 @@ func (c *configuration) DB() (db *DB, err error) { log.Errorf("failed to connect %v, err: %v", report, err) return } - - if sqlDB.Ping() == nil { + sqlDB, err = db.DB.DB() + if err == nil && sqlDB.Ping() == nil { // If the connection is alive, assign the new connection c.db = db log.Infof("%v is connected", report) diff --git a/starter/sqlx/autoconfigure.go b/starter/sqlx/autoconfigure.go index 3261059..3c2aff7 100644 --- a/starter/sqlx/autoconfigure.go +++ b/starter/sqlx/autoconfigure.go @@ -87,8 +87,7 @@ func (c *configuration) DB() (db *DB, err error) { log.Errorf("failed to connect db: %v", err) return } - - if sqlDB.Ping() == nil { + if db.DB.Ping() == nil { // If the connection is alive, assign the new connection c.db = db log.Infof("%v is connected", report)