File tree Expand file tree Collapse file tree 1 file changed +11
-0
lines changed
Expand file tree Collapse file tree 1 file changed +11
-0
lines changed Original file line number Diff line number Diff line change 88 "gorm.io/driver/sqlite"
99 "gorm.io/gorm"
1010 "path/filepath"
11+ "time"
1112)
1213
1314func InitDB () (* gorm.DB , * models.BroadcastChannel ) {
@@ -25,6 +26,16 @@ func InitDB() (*gorm.DB, *models.BroadcastChannel) {
2526 log .Fatal ().Err (err ).Msg ("failed to connect to database" )
2627 }
2728
29+ if EnablePostgres .GetBool () {
30+ sqlDB , err := db .DB ()
31+ if err != nil {
32+ log .Fatal ().Err (err ).Msg ("failed to connect to database" )
33+ }
34+ sqlDB .SetMaxIdleConns (10 ) // SetMaxIdleConns sets the maximum number of connections in the idle connection pool.
35+ sqlDB .SetMaxOpenConns (100 ) // SetMaxOpenConns sets the maximum number of open connections to the database.
36+ sqlDB .SetConnMaxLifetime (time .Hour ) // SetConnMaxLifetime sets the maximum amount of time a connection may be reused.
37+ }
38+
2839 err = db .AutoMigrate (& models.Job {})
2940 if err != nil {
3041 log .Fatal ().Err (err ).Msgf ("failed to migrate database" )
You can’t perform that action at this time.
0 commit comments