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
|
package config
import (
"context"
"database/sql"
"git.anhgelus.world/anhgelus/les-copaings-bot/common"
)
type XpRole struct {
XP uint
RoleID uint64
GuildID uint64
}
func (xp *XpRole) Load(_ context.Context, _ *sql.DB, rows *sql.Rows) error {
return rows.Scan(&xp.XP, &xp.RoleID, &xp.GuildID)
}
func (xp *XpRole) Save(ctx context.Context, db *sql.DB) error {
_, err := db.ExecContext(
ctx,
`INSERT INTO xp_roles (xp, role, guild_id) VALUES (?, ?, ?)`,
xp.XP, xp.RoleID, xp.GuildID,
)
return err
}
func (xp *XpRole) Delete(ctx context.Context, db *sql.DB) error {
_, err := db.ExecContext(
ctx,
`DELETE FROM xp_roles WHERE xp = ? AND role = ? AND guild_id = ?`,
xp.XP, xp.RoleID, xp.GuildID,
)
return err
}
func getXpRoles(ctx context.Context, db *sql.DB, gID uint64) ([]*XpRole, error) {
return common.GetValues[*XpRole](
ctx,
db,
`xp_roles`,
`xp, role, guild_id`,
`guild_id = ?`, gID,
)
}
|