modify random query, update schema
This commit is contained in:
+3
-1
@@ -2,6 +2,7 @@ package model
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
|
"math/rand"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -17,7 +18,8 @@ type Lottery struct {
|
|||||||
// GetRandomLotteryByType -
|
// GetRandomLotteryByType -
|
||||||
func GetRandomLotteryByType(t string) (p *Lottery, err error) {
|
func GetRandomLotteryByType(t string) (p *Lottery, err error) {
|
||||||
p = &Lottery{}
|
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 {
|
if err == sql.ErrNoRows {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
Submodule schema updated: 265d85f0d3...03ae87dcfe
Reference in New Issue
Block a user