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
Suggestion on PostgreSQL INSERT ON CONFLICT (Upsert) #1121
Comments
I think that knex.raw is still the best way to write Upsert statements with KnexJS. Check the issue #54. |
I put together a monkey patch to experiment with upsert. See: It works like this: knex("oauths").insert(oauth).onConflict(["provider", "uid"],{
info: profile,
updated_at: new Date(),
}); |
I wrote a relatively simple function which works for my use cases. It uses |
Nice Suggestion! |
@plurch Very cool. Thank you. |
closing as duplicate #54 |
I tried the solution @plurch mentioned. All good except it didn't escape Given the table definition:
And the below code:
It ends up with the below in the db: My working environment is:
|
I end up using the old school way as below:
|
Hi,
Currently I'm using
knex.raw
forINSERT ON CONFLICT
queries:I want to benefit
knex.insert
and other methods at least part of the query for this type queries. Is there a better way to build this query using any combination of knex.select / knex.raw?The text was updated successfully, but these errors were encountered: