Skip to content

Commit

Permalink
Added connection maximum idle time configuration (#635)
Browse files Browse the repository at this point in the history
This PR add the possibility to configure the connection maximum idle time (https://golang.org/pkg/database/sql/#DB.SetConnMaxIdleTime).

Closes #632

BREAKING CHANGE: Requires Go 1.15 from now on.
  • Loading branch information
ArthurKnoep authored Apr 14, 2021
1 parent 1b7b5ef commit 83cf49c
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 9 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
name: Release
runs-on: ubuntu-latest
container:
image: bepsays/ci-goreleaser:1.13-4
image: bepsays/ci-goreleaser:1.15.1
steps:
- name: Checkout Code
uses: actions/checkout@master
Expand All @@ -24,4 +24,4 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GORELEASER_GITHUB_TOKEN }}
with:
version: latest
args: release --rm-dist
args: release --rm-dist
10 changes: 5 additions & 5 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v1
with:
go-version: 1.13
go-version: 1.15
id: go
- name: Checkout Code
uses: actions/checkout@v1
Expand Down Expand Up @@ -64,7 +64,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v1
with:
go-version: 1.13
go-version: 1.15
id: go
- name: Checkout Code
uses: actions/checkout@v1
Expand Down Expand Up @@ -97,7 +97,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v1
with:
go-version: 1.13
go-version: 1.15
id: go
- name: Checkout Code
uses: actions/checkout@v1
Expand Down Expand Up @@ -139,7 +139,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v1
with:
go-version: 1.13
go-version: 1.15
id: go
- name: Checkout Code
uses: actions/checkout@v1
Expand Down Expand Up @@ -181,7 +181,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v1
with:
go-version: 1.13
go-version: 1.15
id: go
- name: Checkout Code
uses: actions/checkout@v1
Expand Down
6 changes: 5 additions & 1 deletion connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import (
"sync/atomic"
"time"

"github.com/pkg/errors"

"github.com/gobuffalo/pop/v5/internal/defaults"
"github.com/gobuffalo/pop/v5/internal/randx"
"github.com/pkg/errors"
)

// Connections contains all available connections
Expand Down Expand Up @@ -117,6 +118,9 @@ func (c *Connection) Open() error {
if details.ConnMaxLifetime > 0 {
db.SetConnMaxLifetime(details.ConnMaxLifetime)
}
if details.ConnMaxIdleTime > 0 {
db.SetConnMaxIdleTime(details.ConnMaxIdleTime)
}
if details.Unsafe {
db = db.Unsafe()
}
Expand Down
2 changes: 2 additions & 0 deletions connection_details.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ type ConnectionDetails struct {
IdlePool int
// Defaults to 0 "unlimited". See https://golang.org/pkg/database/sql/#DB.SetConnMaxLifetime
ConnMaxLifetime time.Duration
// Defaults to 0 "unlimited". See https://golang.org/pkg/database/sql/#DB.SetConnMaxIdleTime
ConnMaxIdleTime time.Duration
// Defaults to `false`. See https://godoc.org/github.com/jmoiron/sqlx#DB.Unsafe
Unsafe bool
Options map[string]string
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/gobuffalo/pop/v5

go 1.13
go 1.15

replace github.com/mattn/go-sqlite3 => github.com/mattn/go-sqlite3 v1.14.0

Expand Down

0 comments on commit 83cf49c

Please sign in to comment.