feat(rain): add Ignore() support to InsertQuery#154
Conversation
Implements .Ignore() for InsertQuery, providing dialect-native "ignore" behavior: - MySQL: INSERT IGNORE INTO ... - SQLite: INSERT OR IGNORE INTO ... - PostgreSQL: INSERT INTO ... ON CONFLICT DO NOTHING Also unifies this behavior with targetless .OnConflict().DoNothing() calls for improved developer ergonomics and SQL idiomaticity. Co-authored-by: cungminh2710 <8063319+cungminh2710@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
Greptile SummaryThis PR adds ignore support for insert queries. The main changes are:
Confidence Score: 4/5Explicit conflict clauses can be dropped when they are chained with
pkg/rain/query_insert.go
|
| Filename | Overview |
|---|---|
| pkg/rain/query_insert.go | Adds the ignore flag and dialect rendering, but the helper treats Ignore() as overriding explicit conflict clauses. |
| pkg/rain/query_insert_ignore_test.go | Adds coverage for simple ignore inserts and targetless do-nothing behavior across dialects. |
| pkg/rain/query_insert_test.go | Updates MySQL targetless do-nothing expectations to use native ignore syntax. |
Prompt To Fix All With AI
Fix the following 2 code review issues. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 2
pkg/rain/query_insert.go:289-291
**Ignore Overrides Explicit Conflict**
When a caller chains `Ignore()` with an explicit conflict rule, `useIgnore()` returns true from `q.ignore` before looking at the configured conflict action. On MySQL and SQLite this makes `writeConflictClause` skip the conflict clause, so `.Ignore().OnConflict(users.Email).DoUpdateSet(users.Name)` emits only `INSERT IGNORE` or `INSERT OR IGNORE` and silently drops the requested update.
### Issue 2 of 2
pkg/rain/query_insert.go:872-875
**Targetless Update Becomes DoNothing**
With PostgreSQL, `.Ignore().OnConflict().DoUpdateSet(...)` reaches this block with `useIgnore()` true from `q.ignore` and no conflict target. The code emits `ON CONFLICT DO NOTHING`, so the requested update assignments are discarded instead of returning the existing target-required error.
Reviews (1): Last reviewed commit: "feat(rain): add Ignore() support to Inse..." | Re-trigger Greptile
| if q.ignore { | ||
| return true | ||
| } |
There was a problem hiding this comment.
Ignore Overrides Explicit Conflict
When a caller chains Ignore() with an explicit conflict rule, useIgnore() returns true from q.ignore before looking at the configured conflict action. On MySQL and SQLite this makes writeConflictClause skip the conflict clause, so .Ignore().OnConflict(users.Email).DoUpdateSet(users.Name) emits only INSERT IGNORE or INSERT OR IGNORE and silently drops the requested update.
Prompt To Fix With AI
This is a comment left during a code review.
Path: pkg/rain/query_insert.go
Line: 289-291
Comment:
**Ignore Overrides Explicit Conflict**
When a caller chains `Ignore()` with an explicit conflict rule, `useIgnore()` returns true from `q.ignore` before looking at the configured conflict action. On MySQL and SQLite this makes `writeConflictClause` skip the conflict clause, so `.Ignore().OnConflict(users.Email).DoUpdateSet(users.Name)` emits only `INSERT IGNORE` or `INSERT OR IGNORE` and silently drops the requested update.
How can I resolve this? If you propose a fix, please make it concise.| if q.useIgnore() && len(q.conflict.columns) == 0 && q.conflict.constraint == "" { | ||
| ctx.writeString(" DO NOTHING") | ||
| return nil | ||
| } |
There was a problem hiding this comment.
Targetless Update Becomes DoNothing
With PostgreSQL, .Ignore().OnConflict().DoUpdateSet(...) reaches this block with useIgnore() true from q.ignore and no conflict target. The code emits ON CONFLICT DO NOTHING, so the requested update assignments are discarded instead of returning the existing target-required error.
Prompt To Fix With AI
This is a comment left during a code review.
Path: pkg/rain/query_insert.go
Line: 872-875
Comment:
**Targetless Update Becomes DoNothing**
With PostgreSQL, `.Ignore().OnConflict().DoUpdateSet(...)` reaches this block with `useIgnore()` true from `q.ignore` and no conflict target. The code emits `ON CONFLICT DO NOTHING`, so the requested update assignments are discarded instead of returning the existing target-required error.
How can I resolve this? If you propose a fix, please make it concise.
This PR implements the
.Ignore()method for theInsertQuerybuilder, bringing Rain ORM closer to feature parity with Drizzle ORM.Key changes:
Ignore()method toInsertQuery.INSERT INTOrendering to support dialect-specific ignore prefixes (INSERT IGNOREfor MySQL,INSERT OR IGNOREfor SQLite).ON CONFLICT DO NOTHINGwhen ignore is requested.Ignore()with targetlessOnConflict().DoNothing()calls using a new internaluseIgnore()helper.Feature parity target: Drizzle's
.ignore()and targetlessonConflictDoNothing()behavior.PR created automatically by Jules for task 4831643794802559569 started by @cungminh2710