Skip to content

Commit

Permalink
use transation to create
Browse files Browse the repository at this point in the history
  • Loading branch information
ddadaal committed Feb 2, 2024
1 parent b142c1b commit 21e2d5b
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions repositories/summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (r *SummaryRepository) GetAll() ([]*models.Summary, error) {
func (r *SummaryRepository) Insert(summary *models.Summary) error {

if err := r.db.Transaction(func(tx *gorm.DB) error {
if err := r.db.Create(summary).Error; err != nil {
if err := tx.Create(summary).Error; err != nil {
return err
}

Expand Down Expand Up @@ -66,7 +66,7 @@ func (r *SummaryRepository) Insert(summary *models.Summary) error {
itemsToCreate = append(itemsToCreate, item)
}

if err := r.db.Create(itemsToCreate).Error; err != nil {
if err := tx.Create(itemsToCreate).Error; err != nil {
return err
}

Expand Down

0 comments on commit 21e2d5b

Please sign in to comment.