empact/db/team.go

40 lines
941 B
Go
Raw Normal View History

2015-03-05 04:07:02 +07:00
package db
2015-03-06 20:35:13 +07:00
import (
"time"
)
2015-03-06 17:00:04 +07:00
type Team struct {
2015-03-20 21:19:01 +07:00
ID uint64 `json:"id"`
OrgID uint64 `json:"org_id" db:"org_id"`
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 17:00:04 +07:00
}
2015-03-19 19:49:32 +07:00
func (t *Team) Save() {
defer measure("SaveTeam", time.Now())
2015-03-20 21:19:01 +07: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 19:49:32 +07:00
}
2015-03-06 17:00:04 +07:00
func OrgTeams(login string) (teams []*Team) {
2015-03-06 20:35:13 +07:00
defer measure("OrgTeams", time.Now())
2015-03-20 21:19:01 +07:00
mustSelect(&teams, `
select t.*
from teams t
join orgs o on o.id = t.org_id
where o.login = ?
`, login)
2015-03-06 17:00:04 +07:00
return
}