more db refactors

This commit is contained in:
2026-02-09 22:28:52 +11:00
parent a4b4f4f4af
commit 6d5983c376
4 changed files with 18 additions and 22 deletions

View File

@@ -30,8 +30,7 @@ func AssignRole(ctx context.Context, tx bun.Tx, userID, roleID int) error {
RoleID: roleID,
}
err := Insert(tx, userRole).
On("CONFLICT (user_id, role_id) DO NOTHING").
Exec(ctx)
ConflictNothing("user_id", "role_id").Exec(ctx)
if err != nil {
return errors.Wrap(err, "db.Insert")
}
@@ -48,11 +47,10 @@ func RevokeRole(ctx context.Context, tx bun.Tx, userID, roleID int) error {
return errors.New("roleID must be positive")
}
_, err := tx.NewDelete().
Model((*UserRole)(nil)).
err := DeleteItem[UserRole](tx).
Where("user_id = ?", userID).
Where("role_id = ?", roleID).
Exec(ctx)
Delete(ctx)
if err != nil {
return errors.Wrap(err, "tx.NewDelete")
}