claptrap-go/config/database.go
2024-07-08 18:09:43 +02:00

15 lines
380 B
Go

package config
import (
"gorm.io/driver/postgres"
"gorm.io/gorm"
)
func InitDB(config *Config) *gorm.DB {
db, err := gorm.Open(postgres.Open("host=" + config.DatabaseHost + " user=" + config.DatabaseUser + " password=" + config.DatabasePassword + " dbname=" + config.DatabaseName))
if err != nil {
Logger.Sugar().Fatalw("Fail to connect to database", err)
}
return db
}