1
0
Fork 0
empact/db/team.go

39 lines
852 B
Go

package db
import (
"time"
)
type Team struct {
ID int `json:"id"`
OrgID int `json:"org_id"`
Slug string `json:"slug"`
Name string `json:"name"`
Permission string `json:"permission"`
UpdatedAt time.Time `json:"updated_at" db:"updated_at"`
}
func (t *Team) Save() {
defer measure("SaveTeam", time.Now())
mustExecN(`
insert into teams (id, org_id, slug, name, permission, updated_at)
values (:id, :org_id, :slug, :name, :permission, now())
on duplicate key update
slug = values(slug),
name = values(name),
permission = values(permission),
updated_at = now()
`, t)
}
func OrgTeams(login string) (teams []*Team) {
defer measure("OrgTeams", time.Now())
mustSelect(&teams, `
select t.*
from teams t
join orgs o on o.id = t.org_id
where o.login = ?
`, login)
return
}