Knex & pg extension. It adds .onConflictDoNothing() function to knex's quiry builder to support on conflict do nothing
by PostgreSQL.
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();
onConflictDoNothing(): Knex.QueryBuilder
await knex
.insert({ id: 1, name: "John", email: "[email protected]" })
.into("persons")
.onConflictDoNothing();
This lib got inspiration from knex-on-duplicate-update
.