-
-
Notifications
You must be signed in to change notification settings - Fork 353
feat: skip batch insert when unique index exists #1440
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
cdcbeac
7d82d76
d1bf5e3
ad4c750
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -137,6 +137,18 @@ func (b *QueryStructMeta) appendOrUpdateField(f *model.Field) { | |
|
|
||
| func (b *QueryStructMeta) appendField(f *model.Field) { b.Fields = append(b.Fields, f) } | ||
|
|
||
| func (b *QueryStructMeta) HasUniqueIndex() bool { | ||
| for _, f := range b.Fields { | ||
| if f == nil { | ||
| continue | ||
| } | ||
| if len(f.GORMTag[field.TagKeyGormUniqueIndex]) > 0 { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Logic] HasUniqueIndex only checks Context for Agents |
||
| return true | ||
| } | ||
| } | ||
| return false | ||
| } | ||
|
|
||
| // HasField check if BaseStruct has fields | ||
| func (b *QueryStructMeta) HasField() bool { return len(b.Fields) > 0 } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Logic] The PR description says to skip
CreateInBatcheswhen any field has a gorm tag, butHasUniqueIndex()only checksuniqueIndex. Models using other uniqueness-related tags (e.g.,unique,primaryKey) will still run the batch insert and can still fail with duplicate zero values. If the intent is truly “any gorm tag,” consider checking the tag map directly or expanding the tag set you check.Example (if you want any gorm tag to disable batching):
Or include other uniqueness tags as needed.
Context for Agents