From 2db0b3998729d4261db7744afe7e9e1f161dc4f9 Mon Sep 17 00:00:00 2001 From: Geoffrey Bauduin Date: Mon, 1 Feb 2021 11:36:13 +0100 Subject: [PATCH] feat(connections): can now configure max idle time of SQL connections Signed-off-by: Geoffrey Bauduin --- .../github.com/loopfz/gadgeto/zesty/utils/rekordo/database.go | 2 ++ db.go | 2 ++ 2 files changed, 4 insertions(+) diff --git a/_vendor/github.com/loopfz/gadgeto/zesty/utils/rekordo/database.go b/_vendor/github.com/loopfz/gadgeto/zesty/utils/rekordo/database.go index 1e7dbfc..1a49e99 100644 --- a/_vendor/github.com/loopfz/gadgeto/zesty/utils/rekordo/database.go +++ b/_vendor/github.com/loopfz/gadgeto/zesty/utils/rekordo/database.go @@ -26,6 +26,7 @@ type DatabaseConfig struct { MaxIdleConns int AutoCreateTables bool ConnMaxLifetime time.Duration + ConnMaxIdleTime time.Duration } // RegisterDatabase creates a gorp map with tables and tc and @@ -47,6 +48,7 @@ func RegisterDatabase(db *DatabaseConfig, tc gorp.TypeConverter, dialect gorp.Di } dbConn.SetMaxIdleConns(db.MaxIdleConns) dbConn.SetConnMaxLifetime(db.ConnMaxLifetime) + dbConn.SetConnMaxIdleTime(db.ConnMaxIdleTime) // Select the proper dialect used by gorp. if dialect == nil { diff --git a/db.go b/db.go index e0b68eb..61424f7 100644 --- a/db.go +++ b/db.go @@ -58,6 +58,7 @@ type DatabaseConfiguration struct { MaxOpenConns int MaxIdleConns int ConnMaxLifetime time.Duration + ConnMaxIdleTime time.Duration AutoCreateTables bool // Dialect database dialect, leave empty for automatic guessing Dialect gorp.Dialect @@ -92,6 +93,7 @@ func RegisterDB(config *DatabaseConfiguration) error { MaxIdleConns: config.MaxIdleConns, MaxOpenConns: config.MaxOpenConns, ConnMaxLifetime: config.ConnMaxLifetime, + ConnMaxIdleTime: config.ConnMaxIdleTime, } // Register database.