diff options
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, + ) +} |
