You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
584 B
Go

package db_client
import (
"log"
"git.sp4ke.xyz/AnisB/shelf_api_go/config"
"github.com/jmoiron/sqlx"
_ "github.com/lib/pq"
)
var ConnectDB *sqlx.DB
func InitialiseDBConnection() {
config, err := config.LoadConfig(".")
if err != nil {
log.Fatalf("could not load config: %v\n", err)
}
db, err := sqlx.Open(config.PostgresDriver, config.PostgresSource)
if err != nil {
log.Fatalf("could not connect to database: %v\n", err)
}
err = db.Ping()
if err != nil {
log.Fatalf("could not ping database: %v\n", err)
}
ConnectDB = db
}