Enha: tx for cron

This commit is contained in:
Grail Finder
2025-07-04 12:25:20 +03:00
parent 71a2d9d747
commit c2d6812230
5 changed files with 38 additions and 41 deletions

View File

@ -2,6 +2,7 @@ package repos
import (
"context"
"fmt"
"gralias/models"
"github.com/jmoiron/sqlx"
@ -60,10 +61,17 @@ func (p *RepoProvider) PlayerDelete(ctx context.Context, roomID, username string
return err
}
func (p *RepoProvider) PlayerSetRoomID(ctx context.Context, username, roomID string) error {
func (p *RepoProvider) PlayerSetRoomID(ctx context.Context, roomID, username string) error {
db := getDB(ctx, p.DB)
_, err := db.ExecContext(ctx, "UPDATE players SET room_id = ? WHERE username = ?", roomID, username)
return err
res, err := db.ExecContext(ctx, "UPDATE players SET room_id = ? WHERE username = ?", roomID, username)
if err != nil {
return err
}
affected, _ := res.RowsAffected()
if affected == 0 {
return fmt.Errorf("failed to set room_id (%s) for player (%s)", roomID, username)
}
return nil
}
func (p *RepoProvider) PlayerExitRoom(ctx context.Context, username string) error {