1
0
Fork 0
empact/db/repo.go

33 lines
711 B
Go
Raw Normal View History

2015-03-04 19:09:08 +00:00
package db
2015-03-06 11:18:15 +00:00
import (
"time"
)
2015-03-06 10:00:04 +00:00
type Repo struct {
2015-03-06 11:18:15 +00:00
ID uint64 `json:"id"`
Owner string `json:"owner"`
Name string `json:"name"`
UpdatedAt time.Time `json:"updated_at"`
IsPrivate bool `json:"is_private"`
IsForm bool `json:"is_fork"`
2015-03-06 10:00:04 +00:00
}
2015-03-04 19:09:08 +00:00
2015-03-06 11:18:15 +00:00
const orgReposQuery = `select * from repos where owner = ?`
const saveRepoQuery = `
insert into repos (owner, name, updated_at)
2015-03-06 11:29:52 +00:00
values (:owner, :name, now())
2015-03-06 11:18:15 +00:00
on duplicate key update
updated_at=now()`
2015-03-04 19:09:08 +00:00
2015-03-04 20:51:17 +00:00
func (r *Repo) Save() {
2015-03-06 13:35:13 +00:00
defer measure("SaveRepo", time.Now())
2015-03-06 11:29:52 +00:00
mustExecN(saveRepoQuery, r)
2015-03-04 19:09:08 +00:00
}
2015-03-06 11:18:15 +00:00
func OrgRepos(login string) (repos []*Repo) {
2015-03-06 13:35:13 +00:00
defer measure("OrgRepos", time.Now())
2015-03-06 11:29:52 +00:00
mustSelect(&repos, orgReposQuery, login)
2015-03-06 11:18:15 +00:00
return
}