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

46 lines
628 B

package database
import (
"fmt"
"gorm.io/driver/postgres"
"gorm.io/gorm"
"git.tovijaeschke.xyz/tovi/personal_website/variables"
)
var (
DB *gorm.DB
)
func InitDatabaseConn() error {
var (
dbConnString string
err error
)
dbConnString = fmt.Sprintf(
"host=%s port=%d dbname=%s user=%s password=%s %s",
variables.DbHost,
variables.DbPort,
variables.DbName,
variables.DbUser,
variables.DbPass,
variables.DbOpts,
)
DB, err = gorm.Open(
postgres.Open(dbConnString),
&gorm.Config{},
)
if err != nil {
return err
}
err = MigrateDB()
if err != nil {
return err
}
return nil
}