-
Notifications
You must be signed in to change notification settings - Fork 1
/
dao.go
38 lines (33 loc) · 798 Bytes
/
dao.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
33
34
35
36
37
38
package main
import (
"github.com/jinzhu/gorm"
_ "github.com/jinzhu/gorm/dialects/postgres"
"os"
)
type Person struct {
ID uint
Name string `gorm:"size:50; not null"`
Email string `gorm:"size:50; unique; not null"`
}
type Group struct {
ID uint
PersonsCount uint `gorm:"not null"`
Link string `gorm:"unique; not null"`
Closed bool `gorm:"default:false; not null"`
}
type GroupToPerson struct {
ID uint
PersonID uint
GroupID uint
}
func GetDBClient() *gorm.DB {
host := os.Getenv("DB_HOST")
dbName := os.Getenv("DB_NAME")
db, err := gorm.Open("postgres", "host=" + host + " port=6432 user=alexandr dbname=" + dbName + " password=" + os.
Getenv("DB_PASS"))
db.LogMode(true)
if err != nil {
panic(err)
}
return db
}