gographql/postgres/postgres.go

32 lines
517 B
Go
Raw Permalink Normal View History

2019-07-24 16:52:09 +02:00
package postgres
import (
2019-07-25 14:29:02 +02:00
"cadoles/graphql/config"
2019-07-24 16:52:09 +02:00
"database/sql"
"fmt"
_ "github.com/lib/pq"
)
var (
DB *sql.DB
)
func checkErr(err error, DB *sql.DB) {
if err != nil {
panic(err)
}
}
func DBConnect() {
2019-07-25 14:29:02 +02:00
conf := config.GetConfig()
2019-07-24 16:52:09 +02:00
dbinfo := fmt.Sprintf("host=%s port=%s user=%s password=%s dbname=%s sslmode=disable",
2019-07-25 14:29:02 +02:00
conf.DB_HOST, conf.DB_PORT, conf.DB_USER, conf.DB_PASSWORD, conf.DB_NAME)
2019-07-24 16:52:09 +02:00
var err error
DB, err = sql.Open("postgres", dbinfo)
checkErr(err, DB)
}
func DBClose() {
DB.Close()
}