1 回答
TA贡献1829条经验 获得超13个赞
pgx驱动解决方案:
从结构中删除指针
type Token struct {
Id int64 `db:"id"`
Email string `db:"email"`
OperationType string `db:"operation_type"`
Token string `db:"token"`
ExpirationDate time.Time `db:"expiration_date"`
}
重写功能
func (r Repo2) FindOneByEmail(ctx context.Context, email string, ct *Token) error {
var date pgtype.Timestamptz
row := r.DB.QueryRow(`
SELECT id, email, operation_type, token, expiration_date
FROM tokens
WHERE email=$1 AND type=$2 AND expiration_date>$3::date`,
email, "registration", time.Now().UTC(),
)
err := row.Scan(&ct.Id, &ct.Email, &ct.OperationType, &ct.Token, &date)
if err != nil {
return err
}
ct.ExpirationDate = date.Time
return nil
}
- 1 回答
- 0 关注
- 97 浏览
添加回答
举报