Your Question

Hi folks,

Just wondering if there's any way to set the max db connection idle time in the gorm.Open() function configs? I can't find there's any related key in the gorm Config struct.

Like in the codes below,

db, err = gorm.Open(postgres.Open(dataSourceName), &gorm.Config{/*Any available key here?*/})

is there available setting to set the connection max idle time? Or should I only set it by the way way below:

db, err = gorm.Open(postgres.Open(dataSourceName), &gorm.Config{})
if err != nil {
    return nil, err
} else {
    sqlDB, err := db.DB()
    sqlDB.SetConnMaxIdleTime(60 * time.Second)
    if err != nil {
        return nil, err
    }
}

Thanks.

The document you expected this should be explained

Expected answer

Comment From: github-actions[bot]

This issue has been automatically marked as stale because it has been open 360 days with no activity. Remove stale label or comment or this will be closed in 180 days

Comment From: jinzhu

https://gorm.io/docs/generic_interface.html

Comment From: jinzhu

this is the only way to change the db connection idle time currently.