Skip to content
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

New Feature Request: INSERT ON CONFLICT #64

Open
RockfordWei opened this issue May 16, 2019 · 0 comments
Open

New Feature Request: INSERT ON CONFLICT #64

RockfordWei opened this issue May 16, 2019 · 0 comments

Comments

@RockfordWei
Copy link
Contributor

Proposal

Currently, the user has to determine if the database had already stored a duplicated key:

let table = db.table(ARecord.self)
if try table.where(\ARecord.id == record.id).count() > 0 {
   try table.update(record)
} else {
  try table.insert(record)
}

And apparently, the snippet above is low efficient and could not fully use the native SQL for INSERT ON CONFLICT.

The new upsert() or a general save() function should simplify the above code to:

try table.save(record)

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

No branches or pull requests

1 participant