Skip to content

Instantly share code, notes, and snippets.

@dipeshhkc
Last active August 30, 2020 16:57
Show Gist options
  • Save dipeshhkc/aecb22c1eb91f88ce3a59bb9deb1b59d to your computer and use it in GitHub Desktop.
Save dipeshhkc/aecb22c1eb91f88ce3a59bb9deb1b59d to your computer and use it in GitHub Desktop.
package repository
func DB() *gorm.DB {
username:=os.Getenv("DB_USERNAME")
password:=os.Getenv("DB_PASSWORD")
dbname:=os.Getenv("DB_NAME")
db, err := gorm.Open("mysql", username+":"+password+"@/"+dbname+"?charset=utf8&parseTime=True&loc=Local")
if err != nil {
log.Fatal("Error connecting to Database")
return nil
}
db.AutoMigrate(&model.User{}, &model.Product{}, &model.Order{})
return db
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment