refactor(channelserver): standardize on BeginTxx for all repository transactions

Replace db.Begin() with db.BeginTxx(context.Background(), nil) across all
8 remaining call sites in repo_guild.go, repo_guild_rp.go, repo_festa.go,
and repo_event.go. Use deferred Rollback() instead of explicit rollback
at each error return, eliminating 15 manual rollback calls.
This commit is contained in:
Houmgaor
2026-02-22 16:55:59 +01:00
parent 2acbb5d03a
commit 59fd722d37
5 changed files with 30 additions and 38 deletions

View File

@@ -1,6 +1,7 @@
package channelserver
import (
"context"
"database/sql"
"github.com/jmoiron/sqlx"
@@ -181,16 +182,17 @@ func (r *FestaRepository) RegisterGuild(guildID uint32, team string) error {
// SubmitSouls records soul submissions for a character within a transaction.
func (r *FestaRepository) SubmitSouls(charID, guildID uint32, souls []uint16) error {
tx, err := r.db.Begin()
tx, err := r.db.BeginTxx(context.Background(), nil)
if err != nil {
return err
}
defer func() { _ = tx.Rollback() }()
for i, s := range souls {
if s == 0 {
continue
}
if _, err := tx.Exec(`INSERT INTO festa_submissions VALUES ($1, $2, $3, $4, now())`, charID, guildID, i, s); err != nil {
_ = tx.Rollback()
return err
}
}