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

knex-increment-upsert

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

knex-increment-upsert

knex insert on duplicate key update & increment

  • 1.3.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
11
increased by10%
Maintainers
1
Weekly downloads
 
Created
Source

knex-increment-upsert 👋

Documentation Documentation Documentation Maintenance License: MIT

knex insert and on duplicate key update & increment

  • Github
  • npm

📥 Install

npm install knex-increment-upsert

🧩 Requirements

  • knex >= v0.95.0

📖 Usage

incrementUpsert(db, tableName, data, incrementColumns?, updateColumns?, trx?) => Promise<number[]>

  • Single upsert
const { incrementUpsert } = require('knex-increment-upsert');
const knex = require('knex');

const db = knex({ ... });

// Outputs:
// insert into `table1` (`inc1`, `pk1`, `pk2`) values (3, 'pk1', 'pk2') on duplicate key update `inc1` = `inc1` + values(`inc1`)
incrementUpsert(
  db, 
  'table1', 
  {
    pk1: 'pk1',
    pk2: 'pk2',
    inc1: 3,
  }, 
  [ 'inc1' ]
);
  • Batch upsert
// Outputs:
// insert into `table1` (`col1`, `inc1`, `pk1`, `pk2`) values ('1', 1, '1', '1'), ('2', 2, '2', '2') on duplicate key update `inc1` = `inc1` + values(`inc1`),`col1` = values(`col1`)
incrementUpsert(
  db,
  'table1',
  [
    {
      pk1: '1',
      pk2: '1',
      inc1: 1,
      col1: '1'
    },
    {
      pk1: '2',
      pk2: '2',
      inc1: 2,
      col1: '2'
    }
  ],
  [ 'inc1' ],
  [ 'col1' ]
);

🙋‍♂️ Author

🤝 Contributing

Contributions, issues and feature requests are welcome!
Feel free to check issues page.

🌟 Show your support

Give a ⭐️ if this project helped you!

📝 License

Copyright © 2021 a179346.
This project is MIT licensed.


This README was generated with ❤️ by readme-md-generator

Keywords

FAQs

Package last updated on 14 Feb 2022

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