Merge pull request #226 from mr-karan/fix/db-config

Fix/db config
This commit is contained in:
Kailash Nadh 2020-11-17 14:39:46 +05:30 committed by GitHub
commit d9ab365ea1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 8 deletions

View File

@ -4,6 +4,7 @@ import (
"context"
"database/sql"
"fmt"
"time"
"github.com/jmoiron/sqlx"
"github.com/lib/pq"
@ -84,14 +85,15 @@ type Queries struct {
// dbConf contains database config required for connecting to a DB.
type dbConf struct {
Host string `koanf:"host"`
Port int `koanf:"port"`
User string `koanf:"user"`
Password string `koanf:"password"`
DBName string `koanf:"database"`
SSLMode string `koanf:"ssl_mode"`
MaxOpen int `koanf:"max_open"`
MaxIdle int `koanf:"max_idle"`
Host string `koanf:"host"`
Port int `koanf:"port"`
User string `koanf:"user"`
Password string `koanf:"password"`
DBName string `koanf:"database"`
SSLMode string `koanf:"ssl_mode"`
MaxOpen int `koanf:"max_open"`
MaxIdle int `koanf:"max_idle"`
MaxLifetime time.Duration `koanf:"max_lifetime"`
}
// connectDB initializes a database connection.
@ -104,6 +106,7 @@ func connectDB(c dbConf) (*sqlx.DB, error) {
}
db.SetMaxOpenConns(c.MaxOpen)
db.SetMaxIdleConns(c.MaxIdle)
db.SetConnMaxLifetime(c.MaxLifetime)
return db, nil
}

View File

@ -10,3 +10,6 @@
password = "listmonk"
database = "listmonk"
ssl_mode = "disable"
max_open = 25
max_idle = 25
max_lifetime = "300s"

View File

@ -17,3 +17,6 @@
password = "listmonk"
database = "listmonk"
ssl_mode = "disable"
max_open = 25
max_idle = 25
max_lifetime = "300s"