'DELETE query in sequelize.query() method
I am trying to write a delete query in the sequelize.query() method but it is showing me an error stating "errorMessage": "Internal Server Error".
Actually what I am trying to do is that, I want to insert a row into the PostgreSQL table, but if there is a duplication, I was thinking to first delete that entire row and then inserting it again with new values, because I don't want to change just the updated field, rather the complete row.
This is the code of what I am trying to do -
const upsertUser = async (userData) => {
return sequelizeInstance.query(
`
DELETE FROM user_profiles
WHERE email = $1;
INSERT INTO user_profiles
(email, full_name, gender, phone_no, profession, bio, linkedin, codeforces, leetcode, github)
VALUES ( $1, $2, $3, $4, $5, $6, $7, $8, $9, $10 );
`,
{
bind: [
userData.email,
userData.full_name,
userData.gender,
userData.phone_no,
userData.profession,
userData.bio,
userData.linkedin,
userData.codeforces,
userData.leetcode,
userData.github
]
}
)
}
Is there a way, I could achieve the desired functionality ?
The above SQL query is working fine if I write it directly on pgAdmin, but not with Sequelize.
( I am using Sequelize v6, PostgreSQL v14, and pgAdmin 4 )
Thank you in advance.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
