-
Notifications
You must be signed in to change notification settings - Fork 238
Initial documentation on .onConflict, .ignore, and .merge #260
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
Conversation
sections/builder.js
Outdated
| type: "method", | ||
| method: "onConflict", | ||
| example: "insert(..).onConflict(column) / insert(..).onConflict([column1, column2, ...])", | ||
| description: "Utlized by PostgreSQL and Sqlite databases. When chained onto an insert query, it specifies the columns to be used in `ON CONFLICT` clause. A call to .onConflict should always be followed by either .ignore or .update (otherwise it does nothing). In MySQL this method is noop, and .ignore and .merge can be used without .onConflict.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo: Utlized => Utilized
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nicoburns see typo
sections/builder.js
Outdated
| type: "method", | ||
| method: "ignore", | ||
| example: "insert(..).onConflict(..).ignore()", | ||
| description: "Implemented for the PostgreSQL, MySQL, and Sqlite databases. Modifies an insert query, and causes it silently dropped without error if a conflict occurs. Uses INSERT IGNORE in MySQL, and adds an ON CONFLICT (columns) DO NOTHING clause to the insert statement in PostgreSQL and Sqlite.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and causes it to be silently dropped without an error?
sections/builder.js
Outdated
| }, | ||
| { | ||
| type: "text", | ||
| content: "It is also possible to specify data to update seperately from the data to insert. This is useful if you only want to update a subset of the columns. For example, you may want to set a 'created_at' column when inserting, but not wish to update it if the row already exists:" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but would prefer not to update it
1ecd77c to
4b03b42
Compare
4b03b42 to
58cd2c2
Compare
|
Review comments fixed. |
| type: "method", | ||
| method: "merge", | ||
| example: "insert(..).onConflict(..).merge() / insert(..).onConflict(..).merge(updates)", | ||
| description: "Implemented for the PostgreSQL, MySQL, and Sqlite databases. Modifies an insert query, to turn it into an 'upsert' operation. Uses ON DUPLICATE KEY UPDATE in MySQL, and adds an ON CONFLICT (columns) DO UPDATE clause to the insert statement in PostgreSQL and Sqlite.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even that the documentation says how the feature is implemented on each DB, this should also specify explicitly how to write crossdb compatible .merge. For many people from above it still will not be clear that mysql ignores the column list parameter and that actually to have cross db compatible merge, all the columns in the table must be listed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nicoburns Could you please address this comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kibertoad Updated with a note on cross db compatibility.
Documentation for UPSERT pull request: knex/knex#3763