Skip to content

feat(rain): add Ignore() support to InsertQuery#154

Closed
cungminh2710 wants to merge 1 commit into
mainfrom
feat-insert-ignore-4831643794802559569
Closed

feat(rain): add Ignore() support to InsertQuery#154
cungminh2710 wants to merge 1 commit into
mainfrom
feat-insert-ignore-4831643794802559569

Conversation

@cungminh2710

Copy link
Copy Markdown
Contributor

This PR implements the .Ignore() method for the InsertQuery builder, bringing Rain ORM closer to feature parity with Drizzle ORM.

Key changes:

  • Added Ignore() method to InsertQuery.
  • Refactored INSERT INTO rendering to support dialect-specific ignore prefixes (INSERT IGNORE for MySQL, INSERT OR IGNORE for SQLite).
  • Updated PostgreSQL rendering to use ON CONFLICT DO NOTHING when ignore is requested.
  • Unified Ignore() with targetless OnConflict().DoNothing() calls using a new internal useIgnore() helper.
  • Added comprehensive unit tests for all supported dialects and insert variations (values, select, default values).
  • Updated existing MySQL tests to use the new idiomatic syntax.

Feature parity target: Drizzle's .ignore() and targetless onConflictDoNothing() behavior.


PR created automatically by Jules for task 4831643794802559569 started by @cungminh2710

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>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 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 @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

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-apps

greptile-apps Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds ignore support for insert queries. The main changes are:

  • New InsertQuery.Ignore() builder method.
  • Dialect-specific ignore SQL for PostgreSQL, MySQL, and SQLite.
  • Targetless OnConflict().DoNothing() mapped to ignore-style SQL.
  • New SQL rendering tests for ignore insert variants.

Confidence Score: 4/5

Explicit conflict clauses can be dropped when they are chained with Ignore().

  • MySQL and SQLite can skip requested DoUpdateSet clauses.
  • PostgreSQL can turn a targetless update conflict into DO NOTHING.
  • The simple ignore paths are covered by tests, but mixed builder chains need fixes.

pkg/rain/query_insert.go

Important Files Changed

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.

Fix All in Codex

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

Comment thread pkg/rain/query_insert.go
Comment on lines +289 to +291
if q.ignore {
return true
}

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.

P1 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.

Fix in Codex

Comment thread pkg/rain/query_insert.go
Comment on lines +872 to +875
if q.useIgnore() && len(q.conflict.columns) == 0 && q.conflict.constraint == "" {
ctx.writeString(" DO NOTHING")
return nil
}

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.

P1 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.

Fix in Codex

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