Skip to content

Comments

fix: [#858] facades.DB().Insert() can not operate nil columns as expected#1347

Merged
hwbrzzl merged 2 commits intomasterfrom
bowen/#858-1
Jan 10, 2026
Merged

fix: [#858] facades.DB().Insert() can not operate nil columns as expected#1347
hwbrzzl merged 2 commits intomasterfrom
bowen/#858-1

Conversation

@hwbrzzl
Copy link
Contributor

@hwbrzzl hwbrzzl commented Jan 10, 2026

📑 Description

Closes goravel/goravel#858

Follow Gemini

✅ Checks

  • Added test cases for my code

@hwbrzzl hwbrzzl requested a review from a team as a code owner January 10, 2026 13:41
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @hwbrzzl, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request resolves an issue where the DB().Insert() method failed to properly handle nil columns when inserting multiple records into the database. The core change involves a refinement in how column names are identified for the INSERT statement, ensuring that all columns present across any of the input data maps are considered. This enhancement improves the robustness of database insertions, particularly for complex data models involving nested structs and pointer fields that might legitimately hold nil values. The changes are thoroughly validated with new and expanded test cases.

Highlights

  • Fix for Insert Operation with nil Columns: The buildInsert function now correctly handles cases where some columns might be nil in certain data entries. It achieves this by collecting all unique column names from all provided data maps, ensuring that the generated SQL INSERT statement includes all relevant columns, even if their values are nil in some rows.
  • Enhanced ConvertToSliceMap Utility: The ConvertToSliceMap utility has been improved to better handle complex data structures, including nested structs and pointer fields. New test cases validate its ability to correctly process nil pointers and nested struct values when converting Go structs to map[string]any.
  • Comprehensive Test Coverage: New and updated test cases have been added across database/db/utils_test.go and tests/db_test.go to thoroughly validate the Insert operation and ConvertToSliceMap utility, covering various scenarios involving nil values, nested structs, and pointer fields.
  • Improved Snake Case Conversion: A specific test case was added to support/str/str_test.go to ensure that the Snake case conversion correctly transforms 'ID' to 'id', aligning with common database column naming conventions.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@codecov
Copy link

codecov bot commented Jan 10, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 70.27%. Comparing base (42a167d) to head (17478dc).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1347   +/-   ##
=======================================
  Coverage   70.27%   70.27%           
=======================================
  Files         281      281           
  Lines       17121    17121           
=======================================
  Hits        12031    12031           
  Misses       4579     4579           
  Partials      511      511           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request correctly fixes a bug in facades.DB().Insert() that caused issues with batch inserts where rows had different sets of columns, especially when nil values were involved. The new logic now aggregates all unique columns from every row to build a complete and correct INSERT statement. The fix is well-supported by a comprehensive set of new tests covering various scenarios with nil values, pointers, and nested structs. The changes are robust and significantly improve the reliability of batch inserts. I have one minor suggestion to improve test code consistency.

@hwbrzzl hwbrzzl merged commit bedddf4 into master Jan 10, 2026
12 of 13 checks passed
@hwbrzzl hwbrzzl deleted the bowen/#858-1 branch January 10, 2026 14:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

facades.DB().Insert() can not operate nil columns as expected

1 participant