/
db_github.go
79 lines (72 loc) · 2.22 KB
/
db_github.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package user
import (
"github.com/TangSengDaoDao/TangSengDaoDaoServerLib/config"
"github.com/TangSengDaoDao/TangSengDaoDaoServerLib/pkg/db"
"github.com/TangSengDaoDao/TangSengDaoDaoServerLib/pkg/util"
"github.com/gocraft/dbr/v2"
)
type githubDB struct {
session *dbr.Session
ctx *config.Context
}
func newGithubDB(ctx *config.Context) *githubDB {
return &githubDB{
ctx: ctx,
session: ctx.DB(),
}
}
func (d *githubDB) insert(m *githubUserInfoModel) error {
_, err := d.session.InsertInto("github_user").Columns(util.AttrToUnderscore(m)...).Record(m).Exec()
return err
}
func (d *githubDB) insertTx(m *githubUserInfoModel, tx *dbr.Tx) error {
_, err := tx.InsertInto("github_user").Columns(util.AttrToUnderscore(m)...).Record(m).Exec()
return err
}
func (d *githubDB) queryWithLogin(login string) (*githubUserInfoModel, error) {
var m *githubUserInfoModel
_, err := d.session.Select("*").From("github_user").Where("login=?", login).Load(&m)
return m, err
}
type githubUserInfoModel struct {
ID int64
CreatedAt db.Time
UpdatedAt db.Time
Login string
NodeID string
AvatarURL string
GravatarID string
URL string
HtmlUrl string
FollowersURL string
FollowingURL string
GistsURL string
StarredURL string
SubscriptionsURL string
OrganizationsURL string
ReposURL string
EventsURL string
ReceivedEventsURL string
Type string
SiteAdmin bool
Name string
Company string
Blog string
Location string
Email string
Hireable bool
Bio string
TwitterUsername string
PublicRepos int
PublicGists int
Followers int
Following int
GithubCreatedAt string
GithubUpdatedAt string
PrivateGists int
TotalPrivateRepos int
OwnedPrivateRepos int
DiskUsage int
Collaborators int
TwoFactorAuthentication bool
}