Created
May 27, 2019 09:40
-
-
Save sheerlox/65d4451787003622da17c03781083990 to your computer and use it in GitHub Desktop.
How to use ON DUPLICATE KEY UPDATE with Knex.js insert
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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