Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/a179346/knex-increment-upsert
knex insert on duplicate key update & increment
https://github.com/a179346/knex-increment-upsert
increment javascript knex mysql node nodejs on-duplicate-key postgresql query sql sqlite3 typescript upsert
Last synced: about 1 month ago
JSON representation
knex insert on duplicate key update & increment
- Host: GitHub
- URL: https://github.com/a179346/knex-increment-upsert
- Owner: a179346
- License: mit
- Created: 2021-12-15T03:48:55.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2022-02-14T06:56:58.000Z (almost 3 years ago)
- Last Synced: 2024-12-07T16:46:47.835Z (about 2 months ago)
- Topics: increment, javascript, knex, mysql, node, nodejs, on-duplicate-key, postgresql, query, sql, sqlite3, typescript, upsert
- Language: TypeScript
- Homepage:
- Size: 64.5 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
knex-increment-upsert 👋
> knex insert and on duplicate key update & increment
## 🔗 Link
+ [Github](https://github.com/a179346/knex-increment-upsert#readme)
+ [npm](https://www.npmjs.com/package/knex-increment-upsert)## 📥 Install
```sh
npm install knex-increment-upsert
```
## 🧩 Requirements
- knex >= `v0.95.0`## 📖 Usage
> ### `incrementUpsert(db, tableName, data, incrementColumns?, updateColumns?, trx?)` => `Promise`
- #### Single upsert
```js
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
```js
// 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
* Github: [@a179346](https://github.com/a179346)
## 🤝 Contributing
Contributions, issues and feature requests are welcome!
Feel free to check [issues page](https://github.com/a179346/knex-increment-upsert/issues).## 🌟 Show your support
Give a ⭐️ if this project helped you!
## 📝 License
Copyright © 2021 [a179346](https://github.com/a179346).
This project is [MIT](https://github.com/a179346/knex-increment-upsert/blob/main/LICENSE) licensed.***
_This README was generated with ❤️ by [readme-md-generator](https://github.com/kefranabg/readme-md-generator)_