diff options
| author | Anhgelus Morhtuuzh <william@herges.fr> | 2026-03-09 18:47:40 +0100 |
|---|---|---|
| committer | Anhgelus Morhtuuzh <william@herges.fr> | 2026-03-09 18:47:40 +0100 |
| commit | 9c3f1ea5ffe9ad70caf306faff7a3e3948cef6ab (patch) | |
| tree | d7931c65a40a7bf22764473c0dd330f83a4bc071 /config/xp_role.go | |
| parent | 6e92feaba23a4992e0ec4b529660921a6bcb492a (diff) | |
feat(config): preload role reactfeat/leave-gorm
Diffstat (limited to 'config/xp_role.go')
| -rw-r--r-- | config/xp_role.go | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/config/xp_role.go b/config/xp_role.go index f0d57c8..ab684c5 100644 --- a/config/xp_role.go +++ b/config/xp_role.go @@ -2,6 +2,7 @@ package config import ( "context" + "database/sql" "git.anhgelus.world/anhgelus/les-copaings-bot/common" ) @@ -12,8 +13,12 @@ type XpRole struct { GuildID uint64 } -func (xp XpRole) Save(ctx context.Context) error { - _, err := common.GetDB(ctx).ExecContext( +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, @@ -21,11 +26,21 @@ func (xp XpRole) Save(ctx context.Context) error { return err } -func (xp XpRole) Delete(ctx context.Context) error { - _, err := common.GetDB(ctx).ExecContext( +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, + ) +} |
