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-20 15:22:49 +00:00
|
|
|
ID int `json:"id"`
|
2015-03-21 14:12:09 +00:00
|
|
|
OrgID int `json:"org_id" db:"org_id"`
|
2015-03-20 11:43:58 +00:00
|
|
|
Name string `json:"name"`
|
|
|
|
Description string `json:"description"`
|
2015-03-21 14:12:09 +00:00
|
|
|
IsPrivate bool `json:"is_private" db:"is_private"`
|
|
|
|
IsFork bool `json:"is_fork" db:"is_fork"`
|
|
|
|
UpdatedAt time.Time `json:"updated_at" db:"updated_at"`
|
2015-03-06 10:00:04 +00:00
|
|
|
}
|
2015-03-04 19:09:08 +00:00
|
|
|
|
2015-03-04 20:51:17 +00:00
|
|
|
func (r *Repo) Save() {
|
2015-03-21 14:58:40 +00:00
|
|
|
defer measure(time.Now(), "SaveRepo")
|
2015-03-20 11:43:58 +00:00
|
|
|
mustExecN(`
|
2015-03-22 13:26:29 +00:00
|
|
|
insert into repos (id, org_id, name, description, is_private, is_fork, updated_at)
|
|
|
|
values (:id, :org_id, :name, :description, :is_private, :is_fork, now())
|
2015-03-20 11:43:58 +00:00
|
|
|
on duplicate key update
|
2015-03-20 15:32:26 +00:00
|
|
|
org_id = values(org_id),
|
|
|
|
name = values(name),
|
|
|
|
description = values(description),
|
|
|
|
is_private = values(is_private),
|
|
|
|
is_fork = values(is_fork),
|
2015-03-20 14:18:47 +00:00
|
|
|
updated_at = now()
|
2015-03-20 11:43:58 +00:00
|
|
|
`, 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-21 14:58:40 +00:00
|
|
|
defer measure(time.Now(), "OrgRepos")
|
2015-03-20 11:43:58 +00:00
|
|
|
mustSelect(&repos, `
|
|
|
|
select *
|
|
|
|
from repos r
|
|
|
|
left join orgs o on r.org_id = o.id
|
|
|
|
where o.login = ?
|
|
|
|
`, login)
|
2015-03-06 11:18:15 +00:00
|
|
|
return
|
|
|
|
}
|