Skip to content

Commit

Permalink
fix: transaction usage in the identity persister (#404)
Browse files Browse the repository at this point in the history
  • Loading branch information
zepatrik authored May 11, 2020
1 parent b76d380 commit 7f5072d
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions persistence/sql/persister_identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,9 @@ func (p *Persister) CreateIdentity(ctx context.Context, i *identity.Identity) er
return err
}

return sqlcon.HandleError(p.GetConnection(ctx).Transaction(func(tx *pop.Connection) error {
return sqlcon.HandleError(p.Transaction(ctx, func(tx *pop.Connection) error {
ctx := WithTransaction(ctx, tx)

if err := tx.Create(i); err != nil {
return err
}
Expand Down Expand Up @@ -185,7 +187,8 @@ func (p *Persister) UpdateIdentity(ctx context.Context, i *identity.Identity) er
return err
}

return sqlcon.HandleError(p.GetConnection(ctx).Transaction(func(tx *pop.Connection) error {
return sqlcon.HandleError(p.Transaction(ctx, func(tx *pop.Connection) error {
ctx := WithTransaction(ctx, tx)
if count, err := tx.Where("id = ?", i.ID).Count(i); err != nil {
return err
} else if count == 0 {
Expand Down

0 comments on commit 7f5072d

Please sign in to comment.