INNER CODE UNIT · Go
SetupModels
caohoangnam/go-clean-architecture · config/database.go:28
func SetupModels() {
connectionParams := "user=docker password=docker sslmode=disable host=db"
db, err := gorm.Open("postgres", connectionParams)
if err != nil {
return
}
// create table if it does not exist
if !db.HasTable(&domain.Book{}) {
db.CreateTable(&domain.Book{})
}
if !db.HasTable(&domain.Meow{}) {
db.CreateTable(&domain.Meow{})
}
if err != nil {
fmt.Println("Failed to connect to database!", err)
return