Files
2020-03-22 12:33:46 +03:00

40 lines
759 B
Go

package models
import (
"fmt"
"github.com/jinzhu/gorm"
_ "github.com/jinzhu/gorm/dialects/postgres"
"github.com/joho/godotenv"
"os"
)
var db *gorm.DB
func init() {
e := godotenv.Load()
if e != nil {
fmt.Print(e)
}
username := os.Getenv("db_user")
password := os.Getenv("db_pass")
dbName := os.Getenv("db_name")
dbHost := os.Getenv("db_host")
dbUri := fmt.Sprintf("host=%s port=5432 user=%s dbname=%s sslmode=disable password=%s", dbHost, username, dbName, password)
fmt.Println(dbUri)
conn, err := gorm.Open("postgres", "host=localhost port=5432 user=postgres dbname=users sslmode=disable password=#Avrilla8")
if err != nil {
fmt.Print(err)
}
db = conn
db.Debug().AutoMigrate(&Account{})
}
func GetDB() *gorm.DB {
return db
}