Exciting release!Introducing "safe npm". Learn more
Socket
Log inDemoInstall

knex-on-duplicate-update

Package Overview
Dependencies
0
Maintainers
1
Versions
16
Issues
File Explorer

Advanced tools

knex-on-duplicate-update

Simple patcher for Knex. It adds the .onDuplicateUpdate() function to knex's query builder.

    2.3.0latest
    GitHub

Version published
Maintainers
1
Weekly downloads
632
decreased by-0.78%

Weekly downloads

Changelog

Source

v2.3.0

Readme

Source

Knex-onDuplicateUpdate

npm CircleCI

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 --save

or

yarn add knex-on-duplicate-update

Then, 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.QueryBuilder

How 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.

Keywords

FAQs

Last updated on 10 May 2022

Did you know?

Socket installs a Github app to automatically flag issues on every pull request and report the health of your dependencies. Find out what is inside your node modules and prevent malicious activity before you update the dependencies.

Install Socket
Socket
support@socket.devSocket SOC 2 Logo

Product

  • Package Issues
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc