knex-on-duplicate-update
Advanced tools
Comparing version 1.1.1 to 1.1.2
const KnexQueryBuilder = require('knex/lib/query/builder'); | ||
const escapeKnexBinding = input => input.replace(/\?/g, '\\?'); | ||
module.exports.attachOnDuplicateUpdate = function attachOnDuplicateUpdate() { | ||
@@ -31,7 +29,14 @@ KnexQueryBuilder.prototype.onDuplicateUpdate = function (...columns) { | ||
const { | ||
sql: originalSQL, | ||
bindings: originalBindings, | ||
} = this.toSQL(); | ||
const newBindings = [ ...originalBindings, ...bindings ]; | ||
return this.client.raw( | ||
`${escapeKnexBinding(this.toString())} on duplicate key update ${placeholders.join(', ')}`, | ||
bindings | ||
`${originalSQL} on duplicate key update ${placeholders.join(', ')}`, | ||
newBindings, | ||
); | ||
}; | ||
}; |
{ | ||
"name": "knex-on-duplicate-update", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"description": "Simple patcher for Knex. It adds the .onDuplicateUpdate() function to knex's query builder.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
5149
41