1
0
Fork 0

Add save method to org model

This commit is contained in:
Gregory Eremin 2015-03-19 19:49:46 +07:00
parent 755a8ffe53
commit fe9776cc35
1 changed files with 15 additions and 2 deletions

View File

@ -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())