Skip to content

Instantly share code, notes, and snippets.

@sheerlox
Created May 27, 2019 09:40
Show Gist options
  • Save sheerlox/65d4451787003622da17c03781083990 to your computer and use it in GitHub Desktop.
Save sheerlox/65d4451787003622da17c03781083990 to your computer and use it in GitHub Desktop.
How to use ON DUPLICATE KEY UPDATE with Knex.js insert
knex.raw(
await knex
.insert({
a: 1,
b: 2,
c: 3,
d: 4
})
.into('my_table')
.toQuery() +
await knex
.raw(`
ON DUPLICATE KEY UPDATE
a = :a,
b = :b,
d = :d
`, {
a: 1,
b: 2,
d: 4,
})
.toQuery()
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment