Skip to content

Commit

Permalink
Merge pull request knadh#226 from mr-karan/fix/db-config
Browse files Browse the repository at this point in the history
Fix/db config
  • Loading branch information
knadh authored Nov 17, 2020
2 parents c60cc35 + ad8f290 commit d9ab365
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
19 changes: 11 additions & 8 deletions cmd/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"database/sql"
"fmt"
"time"

"github.com/jmoiron/sqlx"
"github.com/lib/pq"
Expand Down Expand Up @@ -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.
Expand All @@ -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
}

Expand Down
3 changes: 3 additions & 0 deletions config-demo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@
password = "listmonk"
database = "listmonk"
ssl_mode = "disable"
max_open = 25
max_idle = 25
max_lifetime = "300s"
3 changes: 3 additions & 0 deletions config.toml.sample
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@
password = "listmonk"
database = "listmonk"
ssl_mode = "disable"
max_open = 25
max_idle = 25
max_lifetime = "300s"

0 comments on commit d9ab365

Please sign in to comment.