1
0
Fork 0
empact/db/org.go

34 lines
808 B
Go
Raw Normal View History

2015-03-05 15:25:26 +00:00
package db
2015-03-06 13:35:13 +00:00
import (
"time"
)
2015-03-06 10:00:04 +00:00
type Org struct {
2015-03-19 12:49:46 +00:00
ID uint64 `json:"id"`
2015-03-06 10:00:04 +00:00
Login string `json:"login"`
2015-03-19 10:04:59 +00:00
Company string `json:"company"`
2015-03-19 12:49:46 +00:00
AvatarURL string `json:"avatar_url" db:"avatar_url"`
2015-03-06 10:00:04 +00:00
}
2015-03-05 15:25:26 +00:00
2015-03-06 10:00:04 +00:00
const userOrgsQuery = `select o.* from members m join orgs o on o.login = m.org where user = ?`
2015-03-19 12:49:46 +00:00
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)
}
2015-03-05 15:25:26 +00:00
2015-03-05 16:06:45 +00:00
func UserOrgs(login string) (orgs []*Org) {
2015-03-06 13:35:13 +00:00
defer measure("UserOrgs", time.Now())
2015-03-06 11:29:52 +00:00
mustSelect(&orgs, userOrgsQuery, login)
2015-03-05 15:25:26 +00:00
return
}