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

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
}

2
schema

@ -1 +1 @@
Subproject commit 265d85f0d3249abb14ee8c925800d2371dd27265
Subproject commit 03ae87dcfe0b20adca876c6ab40e83cedbe2af16