Nika Roffy
Nika Roffy

Reputation: 941

Add multiple values to the postgresql using nodeJS Sequelize

Is there any possible way to add multiple values to the column? Right now i have a comments column and I have this code .

app.put('/addComment/:id', (req, res) => {

Posts.update({
        comment: req.body.comment
    },
    {
        where: {
            id: req.params.id
        }
    }).then((post) => {
    res.send(post)
}).catch((err) => {
    console.log("err", err);
});
})

But instead of adding another value it just updates old one with new , any suggestions on method which will solve my issue?

Upvotes: 0

Views: 223

Answers (1)

xMayank
xMayank

Reputation: 1995

You can use concat function sequelize

It will append new value into the column.

const {fn, col } = models.sequelize

Posts.update({
 members: fn('CONCAT', col("comment"), req.body.comment)
}, {
 where: {
  id: req.params.id
 }
}).then(function() {
 console.log("Value Appended");
});

Upvotes: 2

Related Questions