1
0
Fork 0
empact/db/token.go

26 lines
659 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 {
ID int64 `json:"id"`
User string `json:"user"`
Token string `json:"token"`
Quota int64 `json:"quota"`
Remaining int64 `json:"remaining"`
ResetAt time.Time `json:"reset_at"`
CreatedAt time.Time `json:"created_at"`
}
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)
values (?, ?, ?, ?, ?, now())
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 10:00:04 +00:00
conn.MustExec(saveTokenQuery, t.User, t.Token, t.Quota, t.Remaining, t.ResetAt)
2015-03-05 12:57:36 +00:00
}