Skip to content

Commit

Permalink
Allow setting connection max lifetime (#424)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisgilmerproj authored and stanislas-m committed Aug 25, 2019
1 parent 79000c1 commit 55a7e42
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 3 additions & 0 deletions connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ func (c *Connection) Open() error {
if details.IdlePool != 0 {
db.SetMaxIdleConns(details.IdlePool)
}
if details.ConnMaxLifetime > 0 {
db.SetConnMaxLifetime(details.ConnMaxLifetime)
}
c.Store = &dB{db}

if d, ok := c.Dialect.(afterOpenable); ok {
Expand Down
4 changes: 3 additions & 1 deletion connection_details.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ type ConnectionDetails struct {
Pool int
// Defaults to 2. See https://golang.org/pkg/database/sql/#DB.SetMaxIdleConns
IdlePool int
Options map[string]string
// Defaults to 0 "unlimited". See https://golang.org/pkg/database/sql/#DB.SetConnMaxLifetime
ConnMaxLifetime time.Duration
Options map[string]string
// Query string encoded options from URL. Example: "sslmode=disable"
RawOptions string
}
Expand Down

0 comments on commit 55a7e42

Please sign in to comment.