arimelody.me/db/db.go

25 lines
490 B
Go
Raw Normal View History

package db
import (
"fmt"
"os"
"time"
"github.com/jmoiron/sqlx"
_ "github.com/lib/pq"
)
func InitDatabase() *sqlx.DB {
db, err := sqlx.Connect("postgres", "user=arimelody dbname=arimelody password=fuckingpassword sslmode=disable")
if err != nil {
fmt.Fprintf(os.Stderr, "unable to create database connection pool: %v\n", err)
os.Exit(1)
}
db.SetConnMaxLifetime(time.Minute * 3)
db.SetMaxOpenConns(10)
db.SetMaxIdleConns(10)
return db
}