1
0
Fork 0

Add save method to team model

This commit is contained in:
Gregory Eremin 2015-03-19 19:49:32 +07:00
parent dffc3da24e
commit 755a8ffe53
1 changed files with 17 additions and 4 deletions

View File

@ -5,13 +5,26 @@ import (
)
type Team struct {
ID uint64 `json:"id"`
Slug string `json:"slug"`
Owner string `json:"owner"`
Name string `json:"name"`
ID uint64 `json:"id"`
Slug string `json:"slug"`
Name string `json:"name"`
Permission string `json:"permission"`
OrgID uint64 `json:"org_id" db:"org_id"`
}
const orgTeamsQuery = `select * from teams where owner = ?`
const saveTeamQuery = `
insert into teams (id, slug, name, permission, org_id, created_at, updated_at)
values (:id, :slug, :name, :permission, :org_id, now(), now())
on duplicate key update
slug = values(slug),
permission = values(permission),
updated_at=now()`
func (t *Team) Save() {
defer measure("SaveTeam", time.Now())
mustExecN(saveTeamQuery, t)
}
func OrgTeams(login string) (teams []*Team) {
defer measure("OrgTeams", time.Now())