modify random query, update schema

This commit is contained in:
Jay
2018-09-28 22:09:08 +08:00
parent e1d09bc77b
commit aa1cbb9f04
2 changed files with 4 additions and 2 deletions
+3 -1
View File
@@ -2,6 +2,7 @@ package model
import (
"database/sql"
"math/rand"
"time"
)
@@ -17,7 +18,8 @@ type Lottery struct {
// GetRandomLotteryByType -
func GetRandomLotteryByType(t string) (p *Lottery, err error) {
p = &Lottery{}
err = x.Get(p, `select * from "public"."lottery" where "type" = $1 order by random() limit 1`, t)
offset := rand.Intn(10)
err = x.Get(p, `select * from "public"."lottery" where "type" = $1 order by random() offset $2 limit 1`, t, offset)
if err == sql.ErrNoRows {
return nil, nil
}