Skip to content

Instantly share code, notes, and snippets.

@lewiswalsh
Last active May 27, 2022 18:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lewiswalsh/e296c81d0dbb909937679ed78917712c to your computer and use it in GitHub Desktop.
Save lewiswalsh/e296c81d0dbb909937679ed78917712c to your computer and use it in GitHub Desktop.
KnexJS 'upsert', update on duplicate key else insert #knex #mysql
knex(TABLE_NAME)
.insert({ data : data })
.onConflict(PRIMARY_KEY)
.merge()
.then((res) => {
...
})
.catch((err) => {
...
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment