-
Notifications
You must be signed in to change notification settings - Fork 0
/
market.go
50 lines (42 loc) · 1.18 KB
/
market.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package retropg
import (
"context"
"strconv"
"strings"
"github.com/kralamoure/retro"
"github.com/kralamoure/retro/retrotyp"
)
func (r *Db) Markets(ctx context.Context, gameServerId int) (markets map[string]retro.Market, err error) {
query := "SELECT id, gameserver_id, quantity_1, quantity_2, quantity_3, types, fee, max_level, max_per_account, max_hours" +
" FROM retro.markets" +
" WHERE gameserver_id = $1;"
rows, err := r.pool.Query(ctx, query, gameServerId)
if err != nil {
return
}
defer rows.Close()
markets = make(map[string]retro.Market)
for rows.Next() {
var market retro.Market
var itemTypes string
err = rows.Scan(&market.Id, &market.GameServerId, &market.Quantity1, &market.Quantity2, &market.Quantity3,
&itemTypes, &market.Fee, &market.MaxLevel, &market.MaxPerAccount, &market.MaxHours)
if err != nil {
return
}
if itemTypes != "" {
sli := strings.Split(itemTypes, ",")
market.Types = make([]retrotyp.ItemType, len(sli))
for i, v := range sli {
itemType, err2 := strconv.Atoi(v)
if err2 != nil {
err = err2
return
}
market.Types[i] = retrotyp.ItemType(itemType)
}
}
markets[market.Id] = market
}
return
}