1
0
Fork 0
empact/db/token.go

27 lines
709 B
Go
Raw Normal View History

2015-03-04 20:14:14 +00:00
package db
import (
"time"
)
2015-03-06 10:00:04 +00:00
type Token struct {
2015-03-06 11:18:15 +00:00
ID uint64 `json:"id"`
2015-03-06 10:00:04 +00:00
User string `json:"user"`
Token string `json:"token"`
2015-03-06 11:18:15 +00:00
Quota uint64 `json:"quota"`
Remaining uint64 `json:"remaining"`
2015-03-06 13:23:01 +00:00
ResetAt time.Time `json:"reset_at" db:"reset_at"`
CreatedAt time.Time `json:"created_at" db:"created_at"`
2015-03-06 10:00:04 +00:00
}
2015-03-05 12:57:36 +00:00
2015-03-06 10:00:04 +00:00
const saveTokenQuery = `
insert into tokens (user, token, quota, remaining, reset_at, created_at)
2015-03-06 11:29:52 +00:00
values (:user, :token, :quota, :remaining, :reset_at, now())
2015-03-06 10:00:04 +00:00
on duplicate key update
quota = values(quota), remaining = values(remaining), reset_at = values(reset_at)`
2015-03-05 12:57:36 +00:00
2015-03-05 15:04:44 +00:00
func (t *Token) Save() {
2015-03-06 13:35:13 +00:00
defer measure("SaveToken", time.Now())
2015-03-06 11:29:52 +00:00
mustExecN(saveTokenQuery, t)
2015-03-05 12:57:36 +00:00
}