mtfosbot/model/model.go

29 lines
505 B
Go
Raw Normal View History

2018-08-14 09:25:34 +00:00
package model
import (
"fmt"
"log"
"github.com/jmoiron/sqlx"
2018-08-22 09:20:12 +00:00
_ "github.com/lib/pq"
2018-08-14 09:25:34 +00:00
)
var x *sqlx.DB
// NewDB - connect to database
func NewDB() (*sqlx.DB, error) {
var err error
connStr := fmt.Sprintf("user=%s host=%s sslmode=disable dbname=%s port=%d", "postgres", "localhost", "mtfosbot", 5432)
2018-08-28 03:55:38 +00:00
x, err = sqlx.Connect("postgres", connStr)
2018-08-14 09:25:34 +00:00
if err != nil {
log.Fatal(err)
}
x.SetMaxIdleConns(10)
x.SetMaxOpenConns(200)
err = x.Ping()
if err != nil {
log.Fatal(err)
}
return x, err
}