-
Notifications
You must be signed in to change notification settings - Fork 0
/
aot_raid.go
70 lines (63 loc) · 1.86 KB
/
aot_raid.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package models
import (
"context"
"github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgxpool"
)
type AOTRaid struct {
GuildID int64
AttackerUserID int64
DefenderUserID int64
Reactor int16
Spearmen int
Archers int
}
func AOTRaidByGuildAttacker(ctx context.Context, db *pgxpool.Conn, gid int64, uidAtk int64) (r AOTRaid, err error) {
var rows pgx.Rows
rows, err = db.Query(
ctx,
"SELECT * FROM aot_raid WHERE guild_id = $1 AND attacker_user_id = $2",
gid, uidAtk)
if err == nil {
r, err = pgx.CollectExactlyOneRow(rows, pgx.RowToStructByName[AOTRaid])
}
return
}
func AOTRaidsByGuild(ctx context.Context, db *pgxpool.Conn, gid int64) (rs []AOTRaid, err error) {
var rows pgx.Rows
rows, _ = db.Query(
ctx,
"SELECT * FROM aot_raid WHERE guild_id = $1",
gid)
rs, err = pgx.CollectRows(rows, pgx.RowToStructByName[AOTRaid])
return
}
func (r *AOTRaid) Insert(ctx context.Context, db *pgxpool.Conn) (err error) {
_, err = db.Exec(
ctx,
"INSERT INTO aot_raid(guild_id, attacker_user_id, defender_user_id, reactor, spearmen, archers) "+
"VALUES($1, $2, $3, $4, $5, $6)",
r.GuildID, r.AttackerUserID, r.DefenderUserID, r.Reactor, r.Spearmen, r.Archers)
return
}
func (r *AOTRaid) Update(ctx context.Context, db *pgxpool.Conn, uidDef int64, reactor int16, spearmen int, archers int) (err error) {
_, err = db.Exec(
ctx,
"UPDATE aot_raid SET defender_user_id = $3, reactor = $4, spearmen = $5, archers = $6 "+
"WHERE guild_id = $1 AND attacker_user_id = $2",
r.GuildID, r.AttackerUserID, uidDef, reactor, spearmen, archers)
if err == nil {
r.DefenderUserID = uidDef
r.Reactor = reactor
r.Spearmen = spearmen
r.Archers = archers
}
return
}
func DeleteAOTRaidsByGuild(ctx context.Context, db *pgxpool.Conn, gid int64) (err error) {
_, err = db.Exec(
ctx,
"DELETE FROM aot_raid WHERE guild_id = $1",
gid)
return
}