Skip to content

Conversation

@nicoburns
Copy link
Contributor

Documentation for UPSERT pull request: knex/knex#3763

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.",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: Utlized => Utilized

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nicoburns see typo

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.",
Copy link
Collaborator

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?

},
{
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:"
Copy link
Collaborator

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

@nicoburns nicoburns force-pushed the feature/upsert branch 2 times, most recently from 1ecd77c to 4b03b42 Compare October 28, 2020 00:39
@nicoburns
Copy link
Contributor Author

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.",
Copy link
Member

@elhigu elhigu Oct 28, 2020

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.

knex/knex#3186 (comment)

Copy link
Collaborator

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?

Copy link
Contributor Author

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.

@kibertoad kibertoad merged commit dd3859b into knex:gh-pages Oct 31, 2020
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.

4 participants