Added environment variables
This commit is contained in:
@@ -1,43 +1,34 @@
|
||||
/**
|
||||
* Created by VoidArtanis on 10/22/2017
|
||||
*/
|
||||
|
||||
package shared
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"novatech/config"
|
||||
|
||||
"github.com/jinzhu/gorm"
|
||||
_ "github.com/jinzhu/gorm/dialects/postgres"
|
||||
)
|
||||
|
||||
//import _ "github.com/jinzhu/gorm/dialects/mysql"
|
||||
// import _ "github.com/jinzhu/gorm/dialects/sqlite"
|
||||
// import _ "github.com/jinzhu/gorm/dialects/mssql"
|
||||
|
||||
var db *gorm.DB
|
||||
var err error
|
||||
|
||||
/*
|
||||
dbType can be 'MySql', 'Postrges', ''
|
||||
*/
|
||||
|
||||
func Init() {
|
||||
////MySQL
|
||||
//db, err = gorm.Open("mysql", "user:password@/dbname?charset=utf8&parseTime=True&loc=Local")
|
||||
host := config.AppConfig.Database.HostName
|
||||
user := config.AppConfig.Database.UserName
|
||||
port := config.AppConfig.Database.Port
|
||||
dbName := config.AppConfig.Database.DatabaseName
|
||||
password := config.AppConfig.Database.Password
|
||||
|
||||
dbString:= fmt.Sprintf("postgres, host=%s:%s user=%s dbname=%s sslmode=disable password=%s",host,port,user,dbName,password)
|
||||
|
||||
//PostgreSQL
|
||||
db, err = gorm.Open("postgres", "host=myhost user=gorm dbname=gorm sslmode=disable password=root")
|
||||
|
||||
////SQLite3
|
||||
//db, err = gorm.Open("sqlite3", "/tmp/gorm.db")
|
||||
//
|
||||
////SQL Server
|
||||
//db, err = gorm.Open("mssql", "sqlserver://username:password@localhost:1433?database=dbname")
|
||||
db, err = gorm.Open(dbString)
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
//TODO AUTOMIGRATE models once we have them
|
||||
//db.AutoMigrate(&models.Person{})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user