Enha: tx for cron
This commit is contained in:
		| @@ -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 { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Grail Finder
					Grail Finder