Skip to content

Commit

Permalink
fix: ロールバックの修正
Browse files Browse the repository at this point in the history
  • Loading branch information
KinjiKawaguchi committed Apr 3, 2024
1 parent 2a052b1 commit b942040
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions typing-server/api/repository/score.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package repository

import (
"context"
"database/sql"
"fmt"

"github.com/google/uuid"
Expand Down Expand Up @@ -97,8 +98,15 @@ func CreateScore(ctx context.Context, client *ent.Client, userID uuid.UUID, keys
return err
}
defer func() {
if r := recover(); r != nil {
tx.Rollback()
// txがコミット済みの場合はロールバックしない
if tx == nil {
return
}
if err := tx.Rollback(); err != nil {
if err != sql.ErrTxDone {
return
}
return
}
}()

Expand Down

0 comments on commit b942040

Please sign in to comment.