1 year ago

#75728

test-img

PirateApp

How to differentiate between an update and an insert using sequelize upsert method?

I have a sequelize model where I am doing an upsert like this

ResetToken.upsert({
    accountId,
    token,
}, {
    conflictFields: ['account_id'],
    fields: ['token'],
});

I want to return an HTTP status 201 when a new row is added and a status 200 otherwise How do I distinguish whether the upsert statement actually inserted a new row or just updated an existing row in sequelize?

EDIT 1 My underlying database is postgres 14

sequelize.js

0 Answers

Your Answer

Accepted video resources