Skip to content

Insert with specific unique constraint #56

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

rcarver
Copy link

@rcarver rcarver commented May 28, 2025

This adds an overload of insert where you can specify a specific unique constraint. Currently, upsert behavior is only available for primary key tables, on the primary key.

Given a table with additional unique constraint:

CREATE TABLE referenceFiles (
  id INTEGER PRIMARY KEY AUTOINCREMENT,
  corpus TEXT NOT NULL,
  filePath TEXT NOT NULL,
  UNIQUE(corpus, filePath)
) STRICT

You can upsert by specifying those columns:

ReferenceFile.insert {
  
} onConflict: {
  ($0.corpus, $0.filePath)
} doUpdate: {
  
}

@rcarver rcarver marked this pull request as draft May 28, 2025 02:41
@rcarver rcarver marked this pull request as ready for review May 28, 2025 02:49
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