1
0
Fork 0
empact/db/team.go

40 lines
929 B
Go
Raw Normal View History

2015-03-04 21:07:02 +00:00
package db
2015-03-06 13:35:13 +00:00
import (
"time"
)
2015-03-06 10:00:04 +00:00
type Team struct {
2015-03-20 15:22:49 +00:00
ID int `json:"id"`
OrgID int `json:"org_id"`
2015-03-20 14:19:01 +00:00
Slug string `json:"slug"`
Name string `json:"name"`
Permission string `json:"permission"`
CreatedAt time.Time `json:"created_at" db:"created_at"`
UpdatedAt time.Time `json:"updated_at" db:"updated_at"`
2015-03-06 10:00:04 +00:00
}
2015-03-19 12:49:32 +00:00
func (t *Team) Save() {
defer measure("SaveTeam", time.Now())
2015-03-20 14:19:01 +00:00
mustExecN(`
insert into teams (id, org_id, slug, name, permission, created_at, updated_at)
values (:id, :org_id, :slug, :name, :permission, now(), now())
on duplicate key update
slug = values(slug),
name = values(name),
permission = values(permission),
updated_at = now()
`, t)
2015-03-19 12:49:32 +00:00
}
2015-03-06 10:00:04 +00:00
func OrgTeams(login string) (teams []*Team) {
2015-03-06 13:35:13 +00:00
defer measure("OrgTeams", time.Now())
2015-03-20 14:19:01 +00:00
mustSelect(&teams, `
select t.*
from teams t
join orgs o on o.id = t.org_id
where o.login = ?
`, login)
2015-03-06 10:00:04 +00:00
return
}