2.3.3 • Published 1 year ago
knex-on-duplicate-update v2.3.3
Knex-onDuplicateUpdate
Simple patcher for Knex. It adds the .onDuplicateUpdate() function to knex's query builder in order to add support MySQL's on duplicate key update columnName=Values(columnName).
Note
Knex (v0.21.10) added an official upsert functionality with similar capabilities which supports MySQL, Postgress & SQLite.
How to set up
To use this lib, first you will have to install it:
npm i knex-on-duplicate-update --saveor
yarn add knex-on-duplicate-updateThen, add the following lines to your Knex set up:
const knex = require('knex')(config);
const {attachOnDuplicateUpdate} = require('knex-on-duplicate-update');
attachOnDuplicateUpdate();Function definition
onDuplicateUpdate(...columns: Array<{[key: string]: string} | string>): Knex.QueryBuilderHow to use
Example
await knex.insert({id: 1, name: 'John', email: 'john@mail.com'})
.into('persons')
.onDuplicateUpdate('name', 'email');Setting a fallback value for a column
await knex.insert({id: 1, name: 'John', email: 'john@mail.com'})
.into('persons')
.onDuplicateUpdate('name', {email: 'john-exists@mail.com'});This lib got inspiration from knex-paginator.
2.3.3
1 year ago
2.3.2
2 years ago
2.3.1
2 years ago
2.3.0
4 years ago
2.2.0
4 years ago
2.1.3
4 years ago
2.1.2
4 years ago
2.1.1
5 years ago
2.1.0
5 years ago
2.0.2
5 years ago
2.0.1
5 years ago
2.0.0
5 years ago
1.1.3
6 years ago
1.1.2
6 years ago
1.1.1
6 years ago
1.1.0
6 years ago
1.0.2
6 years ago
1.0.1
7 years ago
1.0.0
7 years ago