Skip to content

Commit

Permalink
Merge pull request #2 from habibrosyad/master
Browse files Browse the repository at this point in the history
Add SetConnMaxLifetime
  • Loading branch information
tsenart authored Jul 15, 2016
2 parents eae74b7 + d3984ac commit c9b4000
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions db.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"database/sql/driver"
"strings"
"sync/atomic"
"time"
)

// DB is a logical database with multiple underlying physical databases
Expand Down Expand Up @@ -121,6 +122,15 @@ func (db *DB) SetMaxOpenConns(n int) {
}
}

// SetConnMaxLifetime sets the maximum amount of time a connection may be reused.
// Expired connections may be closed lazily before reuse.
// If d <= 0, connections are reused forever.
func (db *DB) SetConnMaxLifetime(d time.Duration) {
for i := range db.pdbs {
db.pdbs[i].SetConnMaxLifetime(d)
}
}

// Slave returns one of the physical databases which is a slave
func (db *DB) Slave() *sql.DB {
return db.pdbs[db.slave(len(db.pdbs))]
Expand Down

0 comments on commit c9b4000

Please sign in to comment.