Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

knex-on-duplicate-update

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

knex-on-duplicate-update

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

  • 1.1.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
436
increased by31.72%
Maintainers
1
Weekly downloads
 
Created
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).

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

Package last updated on 05 Sep 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc