Add save method to org model
This commit is contained in:
parent
755a8ffe53
commit
fe9776cc35
17
db/org.go
17
db/org.go
|
@ -5,13 +5,26 @@ import (
|
|||
)
|
||||
|
||||
type Org struct {
|
||||
GithubID uint64 `json:"github_id"`
|
||||
ID uint64 `json:"id"`
|
||||
Login string `json:"login"`
|
||||
Company string `json:"company"`
|
||||
AvatarURL string `json:"avatar_url"`
|
||||
AvatarURL string `json:"avatar_url" db:"avatar_url"`
|
||||
}
|
||||
|
||||
const userOrgsQuery = `select o.* from members m join orgs o on o.login = m.org where user = ?`
|
||||
const saveOrgQuery = `
|
||||
insert into orgs (id, login, company, avatar_url, created_at, updated_at)
|
||||
values (:id, :login, :company, :avatar_url, now(), now())
|
||||
on duplicate key update
|
||||
login = values(login),
|
||||
company = values(company),
|
||||
avatar_url = values(avatar_url),
|
||||
updated_at=now()`
|
||||
|
||||
func (o *Org) Save() {
|
||||
defer measure("SaveOrg", time.Now())
|
||||
mustExecN(saveOrgQuery, o)
|
||||
}
|
||||
|
||||
func UserOrgs(login string) (orgs []*Org) {
|
||||
defer measure("UserOrgs", time.Now())
|
||||
|
|
Loading…
Reference in New Issue