Last active
August 30, 2020 16:57
-
-
Save dipeshhkc/aecb22c1eb91f88ce3a59bb9deb1b59d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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