Skip to content

Commit

Permalink
feat(resource): support batch in BulkUpsert (#71)
Browse files Browse the repository at this point in the history
* feat(resource): support batch in BulkUpsert

* fix: use db session to fix not working batchinsert
  • Loading branch information
rahmatrhd authored Sep 16, 2023
1 parent 3bd8e74 commit 2a882f3
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.Create(models).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 2a882f3

Please sign in to comment.