Skip to content

feat: add savemany#6

Merged
itsLeonB merged 3 commits into
mainfrom
dev
Oct 27, 2025
Merged

feat: add savemany#6
itsLeonB merged 3 commits into
mainfrom
dev

Conversation

@itsLeonB

@itsLeonB itsLeonB commented Oct 21, 2025

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • New Features

    • Added batch-save API to perform bulk save operations in a single transactional call, with input validation and robust error handling to preserve data integrity.
    • Improves performance for workflows that update or insert large sets of records.
  • Tests

    • Added mocking support for the new batch-save operation to enable reliable unit testing and expectations.

@coderabbitai

coderabbitai Bot commented Oct 21, 2025

Copy link
Copy Markdown
Contributor

Warning

Rate limit exceeded

@itsLeonB has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 23 minutes and 9 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 5b3b377 and 0091e00.

📒 Files selected for processing (1)
  • gorm_repository.go (2 hunks)

Walkthrough

Added a new batch-save method SaveMany(ctx context.Context, models []T) ([]T, error) to the public Repository[T] interface, implemented in gormRepository to validate input, obtain a transactional GORM instance, perform a batch Save and return models or wrapped errors; corresponding gomock mock methods were added.

Changes

Cohort / File(s) Summary
Repository implementation
gorm_repository.go
Added SaveMany(ctx context.Context, models []T) ([]T, error) to the Repository[T] interface and implemented gormRepository.SaveMany with non-empty input validation, GetGormInstance(ctx) transactional resolution, db.Save(&models) batch save, and wrapped error returns consistent with InsertMany.
Mocks / Test helpers
gorm_repository_mock.go
Added mock methods for SaveMany: func (m *MockRepository[T]) SaveMany(ctx context.Context, models []T) ([]T, error) and recorder func (mr *MockRepositoryMockRecorder[T]) SaveMany(ctx, models any) *gomock.Call, wiring gomock expectations for the new method.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Repo as gormRepository
    participant DB as Transactional DB

    Client->>Repo: SaveMany(ctx, models)
    alt models empty
        Repo-->>Client: error (empty input)
    else
        Repo->>Repo: GetGormInstance(ctx)
        activate DB
        Repo->>DB: db.Save(&models)
        DB-->>Repo: result / error
        deactivate DB
        alt success
            Repo-->>Client: (models, nil)
        else error
            Repo-->>Client: (nil, wrapped error)
        end
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I hopped through code with a gentle sigh,

Saving many as they flutter by,
Transactions snug, errors caught with care,
Batch by batch, we handle them fair,
A carrot for tests and mocks to share. 🥕

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The pull request title "feat: add savemany" directly and clearly describes the main change in the changeset. The additions of the SaveMany method to the Repository interface, its implementation in gormRepository, and the corresponding mock methods all align with what the title communicates. The title is concise, uses clear language, avoids vague terms or noise, and follows conventional commit format. A team member reviewing the commit history would immediately understand that a SaveMany batch save feature is being introduced.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 770ca19 and f07fdd6.

📒 Files selected for processing (1)
  • gorm_repository.go (2 hunks)
🔇 Additional comments (1)
gorm_repository.go (1)

29-30: LGTM!

The interface method declaration is consistent with other batch operations and clearly documented.

Comment thread gorm_repository.go
@itsLeonB
itsLeonB merged commit 539f459 into main Oct 27, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant