Skip to content

Commit

Permalink
Merge pull request #37 from hidevopsio/refactor/instance-scope
Browse files Browse the repository at this point in the history
fixes the issue that app creash caused by nil sql client
  • Loading branch information
john-deng authored Aug 25, 2024
2 parents e01cf9a + e965385 commit aa1e472
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
4 changes: 2 additions & 2 deletions starter/gorm/autoconfigure.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions starter/sqlx/autoconfigure.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit aa1e472

Please sign in to comment.