2015-03-05 15:04:44 +00:00
|
|
|
package db
|
|
|
|
|
2015-03-06 13:35:13 +00:00
|
|
|
import "time"
|
|
|
|
|
2015-03-06 10:00:04 +00:00
|
|
|
type User struct {
|
|
|
|
Login string `json:"login"`
|
|
|
|
Name string `json:"name"`
|
2015-03-06 11:18:15 +00:00
|
|
|
ID uint64 `json:"id"`
|
2015-03-06 13:23:01 +00:00
|
|
|
AvatarURL string `json:"avatar_url" db:"avatar_url"`
|
2015-03-06 10:00:04 +00:00
|
|
|
}
|
2015-03-05 15:04:44 +00:00
|
|
|
|
2015-03-06 10:00:04 +00:00
|
|
|
const saveUserQuery = `
|
|
|
|
insert into users (login, name, id, avatar_url)
|
2015-03-06 11:29:52 +00:00
|
|
|
values (:login, :name, :id, :avatar_url)
|
2015-03-06 10:00:04 +00:00
|
|
|
on duplicate key update
|
|
|
|
login=values(login), name=values(name), avatar_url=values(avatar_url)`
|
2015-03-05 15:04:44 +00:00
|
|
|
|
|
|
|
func (u *User) Save() {
|
2015-03-06 13:35:13 +00:00
|
|
|
defer measure("SaveUser", time.Now())
|
2015-03-06 11:29:52 +00:00
|
|
|
mustExecN(saveUserQuery, u)
|
2015-03-05 15:04:44 +00:00
|
|
|
}
|