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.
 
 
 

47 lines
703 B

package Database
import (
"fmt"
"gorm.io/driver/postgres"
"gorm.io/gorm"
"PersonalWebsite/Variables"
)
var (
DB *gorm.DB
)
func InitDatabaseConn() error {
var (
dbConnString string
e error
)
// Connect to the postgres db
// you might have to change the connection string to add your database credentials
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, e = gorm.Open(
postgres.Open(dbConnString),
&gorm.Config{},
)
if e != nil {
return e
}
e = MigrateDB()
if e != nil {
return e
}
return nil
}