-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.go
32 lines (28 loc) · 907 Bytes
/
db.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package main
import (
"fmt"
"github.com/jinzhu/gorm"
_ "github.com/jinzhu/gorm/dialects/postgres"
"log"
"os"
)
func getDbConnection() (*gorm.DB, error) {
dbHost, present := os.LookupEnv("NEST_DB_HOST")
if !present {
log.Fatalln("NEST_DB_HOST not set. Please see README for more details.")
}
dbUser, present := os.LookupEnv("NEST_DB_USER")
if !present {
log.Fatalln("NEST_DB_USER not set. Please see README for more details.")
}
dbName, present := os.LookupEnv("NEST_DB_NAME")
if !present {
log.Fatalln("NEST_DB_NAME not set. Please see README for more details.")
}
dbPassword, present := os.LookupEnv("NEST_DB_PASSWORD")
if !present {
log.Fatalln("NEST_DB_PASSWORD not set. Please see README for more details.")
}
dbEndpoint := fmt.Sprintf("host=%s user=%s dbname=%s sslmode=disable password=%s", dbHost, dbUser, dbName, dbPassword)
return gorm.Open("postgres", dbEndpoint)
}