qrz/src/database/main.go
Paul Lecuq 8fac3c0a57
All checks were successful
continuous-integration/drone/push Build is passing
various changes
2020-12-27 15:59:48 +01:00

33 lines
660 B
Go

package database
import (
"fmt"
"log"
"git.paulbsd.com/paulbsd/qrz/src/config"
"git.paulbsd.com/paulbsd/qrz/src/qrz"
_ "github.com/lib/pq"
"xorm.io/xorm"
"xorm.io/xorm/names"
)
// Initialize creates connection to database and exec Schema
func Initialize(config *config.Config) (err error) {
config.Db, err = xorm.NewEngine("postgres",
fmt.Sprintf("postgres://%s:%s@%s/%s",
config.DbUsername,
config.DbPassword,
config.DbHostname,
config.DbName))
if err != nil {
log.Fatalln(err)
}
config.Db.SetMapper(names.GonicMapper{})
config.Db.CreateTables(qrz.Qrz{})
config.Db.Sync2(qrz.Qrz{})
config.Db.ShowSQL(config.Debug)
return
}