Skip to content

askarzh/knex-on-conflict-do-nothing

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

knex-on-conflict-do-nothing

Knex & pg extension. It adds .onConflictDoNothing() function to knex's quiry builder to support on conflict do nothing by PostgreSQL.

How to set up

To use this lib, first you will have to install it:

npm i knex-on-conflict-do-nothing --save

or

yarn add knex-on-conflict-do-nothing

Then, add the following lines to your Knex set up:

const knex = require("knex")(config);

const { attachOnConflictDoNothing } = require("knex-on-conflict-do-nothing");
attachOnConflictDoNothing();

Function definition

onConflictDoNothing(): Knex.QueryBuilder

How to use

Example

await knex
  .insert({ id: 1, name: "John", email: "[email protected]" })
  .into("persons")
  .onConflictDoNothing();

This lib got inspiration from knex-on-duplicate-update.

About

Knex extension to insert on conflict do nothing

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published