commit
d9ab365ea1
|
@ -4,6 +4,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/jmoiron/sqlx"
|
"github.com/jmoiron/sqlx"
|
||||||
"github.com/lib/pq"
|
"github.com/lib/pq"
|
||||||
|
@ -92,6 +93,7 @@ type dbConf struct {
|
||||||
SSLMode string `koanf:"ssl_mode"`
|
SSLMode string `koanf:"ssl_mode"`
|
||||||
MaxOpen int `koanf:"max_open"`
|
MaxOpen int `koanf:"max_open"`
|
||||||
MaxIdle int `koanf:"max_idle"`
|
MaxIdle int `koanf:"max_idle"`
|
||||||
|
MaxLifetime time.Duration `koanf:"max_lifetime"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// connectDB initializes a database connection.
|
// connectDB initializes a database connection.
|
||||||
|
@ -104,6 +106,7 @@ func connectDB(c dbConf) (*sqlx.DB, error) {
|
||||||
}
|
}
|
||||||
db.SetMaxOpenConns(c.MaxOpen)
|
db.SetMaxOpenConns(c.MaxOpen)
|
||||||
db.SetMaxIdleConns(c.MaxIdle)
|
db.SetMaxIdleConns(c.MaxIdle)
|
||||||
|
db.SetConnMaxLifetime(c.MaxLifetime)
|
||||||
return db, nil
|
return db, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,3 +10,6 @@
|
||||||
password = "listmonk"
|
password = "listmonk"
|
||||||
database = "listmonk"
|
database = "listmonk"
|
||||||
ssl_mode = "disable"
|
ssl_mode = "disable"
|
||||||
|
max_open = 25
|
||||||
|
max_idle = 25
|
||||||
|
max_lifetime = "300s"
|
||||||
|
|
|
@ -17,3 +17,6 @@
|
||||||
password = "listmonk"
|
password = "listmonk"
|
||||||
database = "listmonk"
|
database = "listmonk"
|
||||||
ssl_mode = "disable"
|
ssl_mode = "disable"
|
||||||
|
max_open = 25
|
||||||
|
max_idle = 25
|
||||||
|
max_lifetime = "300s"
|
||||||
|
|
Loading…
Reference in New Issue