Skip to content

Commit

Permalink
fix: use db session to fix not working batchinsert
Browse files Browse the repository at this point in the history
  • Loading branch information
rahmatrhd committed Sep 16, 2023
1 parent c3d93eb commit 61e62d7
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion internal/store/postgres/resource_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ func (r *ResourceRepository) BulkUpsert(ctx context.Context, resources []*domain
if len(models) > 0 {
return r.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
// upsert clause is moved to model.Resource.BeforeCreate() (gorm's hook) to apply the same for associations (model.Resource.Children)
if err := r.db.CreateInBatches(models, 1000).Error; err != nil {
if err := r.db.
Session(&gorm.Session{CreateBatchSize: 1000}).
Create(models).Error; err != nil {
return err
}

Expand Down

0 comments on commit 61e62d7

Please sign in to comment.