forked from TechEmpower/FrameworkBenchmarks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
world.go
31 lines (26 loc) · 800 Bytes
/
world.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package models
import (
"log"
"math/rand"
"github.com/astaxie/beego/orm"
)
type World struct {
Id uint16 `orm:"pk" json:"id"`
RandomNumber uint16 `orm:"column(randomNumber)" json:"randomNumber"`
}
const WorldSelect = "SELECT id, randomNumber FROM World WHERE id = ?"
const WorldUpdate = "UPDATE World SET randomNumber = ? WHERE id = ?"
const WorldRowCount = 10000
func GetQueriesWorld(queries int) *[]World {
o := orm.NewOrm()
ww := make([]World, queries)
for i := 0; i < queries; i++ {
err := o.Raw(WorldSelect, rand.Intn(WorldRowCount)+1).QueryRow(&ww[i])
if err != nil {
log.Fatalf("Error scanning world row: %v", err)
}
ww[i].RandomNumber = uint16(rand.Intn(WorldRowCount) + 1)
_, err = o.Raw(WorldUpdate, ww[i].RandomNumber, ww[i].Id).Exec()
}
return &ww
}